嗨,伙计们,所以我对xml有问题,它在节点之前有,我不知道如何用xpath正确处理这个问题,所以xml看起来像这个
<xml>
<item>
-<description>
-<type>
</type>
</description>
</item>
</xml>
那么,在有人浪费时间给出错误答案之前,我该如何导航到xpath中说type我已经尝试了$xml->item->description->type的正常方法在这种情况下不起作用我不知道,因为它不是名称中的非法字符如何处理-前th节点
我认为指出/xml/item/description/type
确实有效(在XmlSpy中的XPath 1.0和2.0中)并不浪费时间。
也就是说,我认为您可能并不真的希望xml中包含这些'-'字符。也许一个更好的问题是"如何从xml中去除无关的'-'字符?"
编辑:
以下是一些改编自SimpleXMLElement文档的PHP,向您展示我没有撒谎:
<?php
$string =
"<xml>
<item>
-<description>
-<type>
Hello World!
</type>
</description>
</item>
</xml>";
$xml = new SimpleXMLElement($string);
$path = '/xml/item/description/type';
$result = $xml->xpath('/xml/item/description/type');
while(list( , $node) = each($result)) {
echo '$path: ',$node,"n";
}
?>
输出:
/xml/item/description/type:
Hello World!
如果您需要任何进一步的帮助,请提供一个简短的例子来重现这个问题。
(如果我的PHP不好,我很抱歉,我有点生疏)