大家好,所以我有一个xml的问题,它有 - 在节点之前,我不知道如何正确处理xpath,所以xml看起来像这样
<xml>
<item>
-<description>
-<type>
</type>
</description>
</item>
</xml>
所以我怎么能在任何人浪费任何时间给出错误的答案之前导航下来说xpath中的类型我已经尝试了$ xml-&gt; item-&gt; description-&gt;的常规方法类型这不起作用在这种情况下,我不知道它不是名称中的非法字符如何处理 - 节点之前
答案 0 :(得分:2)
我认为指出/xml/item/description/type
实际上工作(在XmlSpy的XPath 1.0和2.0中)是浪费时间。
那就是说,我想也许你真的不想在你的xml中使用' - '字符。或许更好的问题是“如何从xml中删除无关的' - '字符?”
编辑:
这是一些改编自SimpleXMLElement documentation的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很糟糕,我有点生疏)