我有以下 XML 文件(如下),我想获取根节点名称的挂钩。
我尝试了以下方法:
$config = simplexml_load_string($xml_data);
echo $config->getName();
哪个回声不算什么。我也迭代了结果,但它从根节点的子节点开始
foreach($config as $key => $value)
{
echo $key;
}
// echo's ReturnStatus, SearchURL and PropertyResults
我只想要根节点“SearchResponse”的名称。我似乎在 SimpleXMLElement 类文档中找不到任何可以帮助http://www.php.net/manual/en/class.simplexmlelement.php
<?xml version="1.0" encoding="ISO-8859-1" ?>
<SearchResponse>
<ReturnStatus>
<Success>
<data>true</data>
<data2>true</data2>
</Success>
<Success>
<data>false</data>
<data2>true</data2>
</Success>
<Exception />
</ReturnStatus>
<SearchURL />
<PropertyResults>
<PropertyResult>
<PropertyID>1468830</PropertyID>
<PropertyName>Sands Acapulco</PropertyName>
</PropertyResult>
<PropertyResult>
<PropertyID>1353302</PropertyID>
<PropertyName>Acapulco Turquesa</PropertyName>
</PropertyResult>
<PropertyResult>
<PropertyID>4521565</PropertyID>
<PropertyName>Almaria Delsonto</PropertyName>
</PropertyResult>
</PropertyResults>
</SearchResponse>