Xpath to select all and exclude child and its children

情到浓时终转凉″ 提交于 2019-12-04 11:00:19

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)]

Here is a link to the result in XPath Tester

XPath can only select whole subtrees, not change them or create new XML output.

If you select the //Orders element, it will always include the <Rejected/> ones. All you can do is eg. select all orders not rejected, but at the same time you will lose the nodes around:

//Orders/*[not(self::Rejected)]

Depending on how you use XPath, you might use it to actually delete the <Rejected/> elements by selecting them using XPath and then deleting it with the XML framework of your primary programming language.

If you want to create new results from an XML language, you have to use XSLT templates or XQuery (which is very close at XPath). Which better fits your problem depends on your actual requirements and needs.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!