XPath通过另一个节点内指定的表达式查找节点 [英] XPath to find a node by expression specified within another node

查看:90
本文介绍了XPath通过另一个节点内指定的表达式查找节点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须通过为每个项目输入一个单独的XPath(1.0)来创建XML映射;正常工作,直到我得到这样的XML文档:

I have to create an XML mapping by entering one single XPath (1.0) for each item; worked fine until I now got an XML document like this:

<PARTIES>       
        <PARTY>         
                <PARTY_ID type="supplier_specific">12345</PARTY_ID>
                <ADDRESS>
                        <NAME>A</NAME>
                </ADDRESS>
        </PARTY>        
        <PARTY>         
                <PARTY_ID type="buyer_specific">54321</PARTY_ID>
                <ADDRESS>
                        <NAME>B</NAME>
                </ADDRESS>
        </PARTY>        
        <PARTY>         
                <PARTY_ID>delivery</PARTY_ID>
                <ADDRESS>       
                        <NAME>C</NAME>
                </ADDRESS>      
        </PARTY>        

        <PARTIES_REFERENCE>
                <BUYER_IDREF type="supplier_specific">12345</BUYER_IDREF>
                <SUPPLIER_IDREF type="buyer_specific">54321</SUPPLIER_IDREF>
                <DELIVERY_IDREF>delivery</DELIVERY_IDREF>
        </PARTIES_REFERENCE>

</PARTIES>

这个想法是:如果您要交付地址,请查看< DELIVERY_IDREF>,从那里获取标识符(交付"),然后查找具有相同标识符的< PARTY>< PARTY_ID>.结果是< ADDRESS>处于相同的水平.

The idea is: if you want the delivery addres, then look at <DELIVERY_IDREF>, take the identifier from there ("delivery") and look for a <PARTY><PARTY_ID> with the same identifier. Result is the <ADDRESS> at the very same level.

因此,如果我想知道收信人地址的< NAME>-如何使用单个 XPath 1.0表达式到达那里?我已经做了大量的映射,但是,如果可能的话,这似乎是下一个层次.

So, if I want to know the <NAME> of the delivery address - how do I get there with a single XPath 1.0 expression? I have done quite a number of mappings, but this seems to be the next level, if possible at all.

推荐答案

就像这样:

/PARTIES/PARTY[./PARTY_ID=/PARTIES/PARTIES_REFERENCE/DELIVERY_IDREF/text()]/ADDRESS/NAME/text()

这篇关于XPath通过另一个节点内指定的表达式查找节点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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