XPath 和多个条件
我的问题是我的 XPATH 规则无法正常工作。我希望它选择 DataFile 元素属性 Filename 不是“thing.xml”的所有 XML。我还添加了示例 XML,以便于理解。
这是我的 XPATH 规则:
/document[transport/sender[code='12345678'] and metaxml/LetterMetaData[Type='invoice'] and SignedDoc/DataFile[@Filename!='thing.xml']]
这是我希望我的 XPATH 规则忽略的 XML:
<document>
<transport>
<sender>
<code>12345678</code>
</sender>
</transport>
<metaxml>
<LetterMetaData>
<Type>invoice</Type>
</LetterMetaData>
</metaxml>
<SignedDoc>
<DataFile Filename="thing.xml">...</DataFile>
</SignedDoc>
</document>
这是我希望我的 XPATH 规则不忽略的 XML:
<document>
<transport>
<sender>
<code>12345678</code>
</sender>
</transport>
<metaxml>
<LetterMetaData>
<Type>invoice</Type>
</LetterMetaData>
</metaxml>
<SignedDoc>
<DataFile Filename="file_with_other_name_than_thing.xml">...</DataFile>
</SignedDoc>
</document>
My problem is my XPATH rule doesn't work correctly. I want it to select all the XML's where DataFile element attribute Filename is not "thing.xml". I also added the sample XML's for easier understanding.
This is my XPATH rule:
/document[transport/sender[code='12345678'] and metaxml/LetterMetaData[Type='invoice'] and SignedDoc/DataFile[@Filename!='thing.xml']]
Here's the XML I want my XPATH rule to ignore:
<document>
<transport>
<sender>
<code>12345678</code>
</sender>
</transport>
<metaxml>
<LetterMetaData>
<Type>invoice</Type>
</LetterMetaData>
</metaxml>
<SignedDoc>
<DataFile Filename="thing.xml">...</DataFile>
</SignedDoc>
</document>
Here's the XML I want my XPATH rule not to ignore:
<document>
<transport>
<sender>
<code>12345678</code>
</sender>
</transport>
<metaxml>
<LetterMetaData>
<Type>invoice</Type>
</LetterMetaData>
</metaxml>
<SignedDoc>
<DataFile Filename="file_with_other_name_than_thing.xml">...</DataFile>
</SignedDoc>
</document>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
哪个是根节点 (
/
) 的子节点?如果您的文档格式良好,则不应是document
并且您的 XPath 评估结果为零。例如,以下 XPath:应用于此输入:
仅返回第二个文档节点。请注意,root 的子级是
docs
。如果您不想选择从根开始,您应该使用
//
:Which is the child of the root node (
/
)? If your document is well formed should not bedocument
and your XPath is evaluating to nothing. For instance, the following XPath:applied on this input:
returns the second document node only. Notice that root's child is
docs
.if you don't want to select starting from the root you should use
//
: