我正在尝试从多个嵌套属性中提取信息(可能是错误的术语)。
XML 字符串:
<?xml version='1.0' encoding='UTF-8'?>
<eveapi version="2">
<currentTime>2013-10-01 18:00:01</currentTime>
<result>
<rowset name="members" key="characterID" columns="characterID, name">
<row characterID="2234" name="Bob">
<rowset name="roles" key="roleID" columns="roleID,roleName" />
<rowset name="grantableRoles" key="roleID" columns="roleID,roleName" />
<rowset name="rolesAtHQ" key="roleID" columns="roleID,roleName" />
<rowset name="grantableRolesAtHQ" key="roleID" columns="roleID,roleName" />
<rowset name="rolesAtBase" key="roleID" columns="roleID,roleName" />
<rowset name="grantableRolesAtBase" key="roleID" columns="roleID,roleName" />
<rowset name="rolesAtOther" key="roleID" columns="roleID,roleName" />
<rowset name="grantableRolesAtOther" key="roleID" columns="roleID,roleName" />
<rowset name="titles" key="titleID" columns="titleID,titleName">
<row titleID="256" titleName="Tiger" />
</rowset>
</row>
<row characterID="555" name="John">
<rowset name="roles" key="roleID" columns="roleID,roleName" />
<rowset name="grantableRoles" key="roleID" columns="roleID,roleName" />
<rowset name="rolesAtHQ" key="roleID" columns="roleID,roleName" />
<rowset name="grantableRolesAtHQ" key="roleID" columns="roleID,roleName" />
<rowset name="rolesAtBase" key="roleID" columns="roleID,roleName" />
<rowset name="grantableRolesAtBase" key="roleID" columns="roleID,roleName" />
<rowset name="rolesAtOther" key="roleID" columns="roleID,roleName" />
<rowset name="grantableRolesAtOther" key="roleID" columns="roleID,roleName" />
<rowset name="titles" key="titleID" columns="titleID,titleName">
<row titleID="16" titleName="R & D" />
<row titleID="64" titleName="Miner" />
<row titleID="256" titleName="Tiger" />
<row titleID="16384" titleName="POS Manager" />
</rowset>
</row>
</rowset>
</result>
<cachedUntil>2013-10-01 18:57:01</cachedUntil>
</eveapi>
这是我今天的PHP:
$simpleXML = simplexml_load_string($xml); // Load XML string data into the simplexml object parser
foreach ($simpleXML->result->rowset->row as $row) {
$name = $row->attributes()->name;
$characterID = $row->attributes()->characterID;
foreach ($row->rowset as $value) {
$titleName .= $value->row->attributes()->titleName.',';
}
echo $Name.'<br>';
echo $titleName.'<br>';
}
我想为每个名称输出的是:
鲍勃
老虎
约翰
研发,矿工,老虎,POS经理