1
我有以下的XML文件(下面),我想获得根节点名称的钩子。如何使用PHP在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>
您的代码[适合我](http://codepad.org/ggvVydOF)... – DaveRandom 2012-04-17 16:48:48
对我而言,它也可以工作 – 2012-04-17 16:48:59
是的,你的权利,这个工作,我忘了包括的一件事是Zend_Config_Xml抽象我正在使用。这似乎限制了你无法访问根节点。我会抛弃它并坚持原生PHP。谢谢。 – 2012-04-17 16:57:08