本文介绍了Xpath选择全部并排除子代及其子代的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我下面有数据,我试图选择除RejectedRecords及其所有子项之外的所有节点.
I have the Data below and I am trying to select all the nodes except RejectedRecords and all of its children.
<?xml version="1.0" encoding="UTF-8"?>
<inmsg>
<BPDATA>
<DATE_TIME>10072014084945</DATE_TIME>
</BPDATA>
<Orders>
<Rejected>
<RejectedRecords>
<RecordNumber>1</RecordNumber>
<RecordError>State Code is invalid</RecordError>
</RejectedRecords>
<RejectedRecords>
<RecordNumber>2</RecordNumber>
<RecordError>State Code is invalid</RecordError>
</RejectedRecords>
<FileName>Foo1.txt</FileName>
<MessageType>Rejected</MessageType>
<RecordCount>2</RecordCount>
<TotalAmount>1050.01</TotalAmount>
</Rejected>
<Unrestricted>
<FileName>Foo2.txt</FileName>
<MessageType>UnrestrictedState</MessageType>
<RecordCount>2</RecordCount>
<TotalAmount>100.10</TotalAmount>
</Unrestricted>
</Orders>
<PrimaryDocument SCIObjectID="6442821469081a3a3node1"/>
</inmsg>
我尝试了许多语句,例如
I have tried a number of statements such as
//*/node()[not(parent::RejectedRecords) and not(self::RejectedRecords) and not(self::RecordNumber) and not(self::RecordError)]
//*[not(parent::RejectedRecords) and not(self::RejectedRecords)]
//*[not(descendant-or-self::RejectedRecords)]
无论我用什么,我仍然会得到RejectedRecords节点及其子节点,因为它与Rejected节点一起出现.我在做什么错了?
No matter what I have used I am still getting the RejectedRecords node and its children because it is coming in with the Rejected node. What am I doing wrong?
推荐答案
此表达式选择所有个节点,但结果集中不包含任何RejectedRecords
或具有作为祖先:
This expression selects all nodes, but does not include in the result set any nodes that are RejectedRecords
or that have RejectedRecords
as an ancestor:
//*[not(descendant::RejectedRecords) and not(ancestor-or-self::RejectedRecords)]
此处是 XPath测试器
这篇关于Xpath选择全部并排除子代及其子代的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!