选择所有但排除某些子子项 [英] Select all but exclude certain subchildren

查看:25
本文介绍了选择所有但排除某些子子项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是想从我的 xpath 选择中排除某个元素(在示例中,exclude),但是我的 xpath 不起作用.

I simply would like to exclude a certain element (in the example, exclude) from my xpath select however my xpath is not working.

XML

 <root>
      <x>
        <y>
          <z>
            <exclude me="please"></exclude>
          </z>
        </y>
      </x>
      <x>
        <y>
          <z>
            <exclude me="please"></exclude>
          </z>
        </y>
      </x>
    </root>


XPath:
/*[not(self::exclude)] 返回整个 XML
/*[node()!=exclude] 返回整个 XML
/root//x//y//z/*[not(self::exclude)](这实际上返回了我不想要的节点)
+ 更多的迭代


XPath:
/*[not(self::exclude)] Returns entire XML
/*[node()!=exclude] Returns entire XML
/root//x//y//z/*[not(self::exclude)] (this actually returns the very node I do not want)
+ many more iterations

我希望返回结果是:

    <root>
      <x>
        <y>
          <z>
          </z>
        </y>
      </x>
      <x>
        <y>
          <z>
          </z>
        </y>
      </x>
    </root>

至少我想选择除 me 属性之外的所有属性.这可能吗?我开始得出结论,事实并非如此.谢谢.

At the very least I would like to select all but the me attribute. Is this possible? I am starting to come to the conclusion that it is not. Thank you.

BizTalk 代码:

BizTalk Code:

construct msgException{
msgException = msgReservationMultiPartIn.NewMessagePart;
xpath(msgException,"//*[not(self::exclude)]");
}

推荐答案

首先,如果 http://codebeautify.org/Xpath-Tester 返回 exclude 元素节点作为

First of all, if http://codebeautify.org/Xpath-Tester returns the exclude element node as the result of

/root//x//y//z/*[not(self::exclude)]

你不应该再使用它.此外,如您所见,其他三个网站没有返回任何内容.

You should never use it again. Also, as you have seen, three other sites returned nothing.

我会说你的 XPath 表达式是明智的(嗯,其中一些是).但是你不能很好地看到——因为会发生以下情况:使用像

Your XPath expressions are sensible I'd say (well, some of them are). But you cannot see that very well - because the following happens: With an expression like

//*[not(self::exclude)]

exclude 节点实际上根本没有被选中.但是:那些在线测试人员返回结果节点及其所有内容,因此像 /root 这样的简单表达式会生成整个 XML 文件(至少带有 http://xpath.online-toolz.com/tools/xpath-editor.php).

the exclude node is really not selected at all. But: Those online testers return result nodes with all their content, so a simple expression like /root yields the whole XML file (at least with http://xpath.online-toolz.com/tools/xpath-editor.php).

对于表达式 //*[not(self::exclude)] 相同的 XPath 测试器返回:

For the expression //*[not(self::exclude)] the same XPath tester returns:

<root>
<x>
<y>
<z>
<exclude me="please"/>
</z>
</y>
</x>
<x>
<y>
<z>
<exclude me="please"/>
</z>
</y>
</x>
</root>
-----------------------
<x>
<y>
<z>
<exclude me="please"/>
</z>
</y>
</x>
-----------------------
<y>
<z>
<exclude me="please"/>
</z>
</y>
-----------------------
<z>
<exclude me="please"/>
</z>
-----------------------
<x>
<y>
<z>
<exclude me="please"/>
</z>
</y>
</x>
-----------------------
<y>
<z>
<exclude me="please"/>
</z>
</y>
-----------------------
<z>
<exclude me="please"/>
</z>

单个结果以--------分隔,并且,如你所见,exclude节点并没有单独出现在结果中- 就像它的父代和祖先被选择和返回的副产品一样.

Individual results are separated by --------, and, as you can see, the exclude node does not appear in the results on its own - just as the by-product of its parent and ancestors being selected and returned.

这是什么意思?

在您使用 XPath 的环境中并行开发您的 XPath 表达式(在您的情况下,如果我理解正确的话,是 Biztalk).然后,如果返回错误的元素,请返回此处,发布完整代码并寻求帮助.

Develop your XPath expressions in parallel with the environment you use XPath in (in your case, if I have understood correctly, Biztalk). Then, if the wrong elements are returned, come back here, post the complete code and get help.

这篇关于选择所有但排除某些子子项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆