祖先:: XML语法 [英] ancestor:: XML syntax

查看:74
本文介绍了祖先:: XML语法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



是否有人熟悉使用祖先的正确语法::?


我试图在ac#应用程序中使用它,我是还在名为Cooktop的

解析器应​​用程序中进行测试( http:// www。 xmlcooktop.com


我无法使用它或我的c#代码在使用祖先时返回节点列表。

是祖先::某事.NET支持还是不支持?


示例,这些都不起作用:


nodes:// pallet / ancestor :: position

<! - nodes xpath // pallet / ancestor :: position'' - >

<! - nodes xpath parent :: * / pallet / position / *'' - >

<! - nodes xpath parent :: * // pallet / position / *'' - >

<! - nodes xpath / ancestor :: position / client [@id =''MDR'']'' - >

<! - nodes xpath / pallet / ancestor: :position / client [@id =''MDR'']'' - >

<! - 节点xpath / pallet / position / ancestor :: client [@id =''MDR'']'' - >


for

< pallet> ;

< position row =" 0"托架= QUOT; 0" level =" A">

< client id =" HAL">

< partnum id =" HA0132-1033" isStock =" N"> HA0132-1033< / partnum>

< partnum id =" HA9027EP" isStock =" Y"> HA9027EP< / partnum>

< / client>

< client id =" MDR">

< partnum id =" A / P FILES" isStock =" N"> A / P FILES< / partnum>

< / client>

< client id =" OPS">

< partnum id =" OPS" isStock =" N" OPS

< / partnum>< / client>

< / position>

< position row =" 1"托架= QUOT 1 QUOT; level =" B">

< client id =" MDR">

< partnum id =" A / P FILES" isStock =" N" A / P FILES

< / partnum>

< / client>

< / position> ;

< position row =" 1"托架= QUOT 1 QUOT; level =" D">

< client id =" MDR">

< partnum id =" X-MAS DECORATION&qu​​ot; isStock =" N"> X-MAS装饰

< / partnum>

< / client>

< / pallet> ;


Is anyone familar with the correct syntax for using ancestor:: ?

I am trying to use it in a c# application, and I am also testing it in a
parser application called Cooktop ( http://www.xmlcooktop.com )

I cannot get it or my c# code to return a node list when using ancestor.
Is ancestor:: something that .NET does or does not support?

Examples, none of these work:

nodes://pallet/ancestor::position
<!--nodes xpath //pallet/ancestor::position''-->
<!--nodes xpath parent::*/pallet/position/*''-->
<!--nodes xpath parent::*//pallet/position/*''-->
<!--nodes xpath /ancestor::position/client[@id=''MDR'']''-->
<!--nodes xpath /pallet/ancestor::position/client[@id=''MDR'']''-->
<!--nodes xpath /pallet/position/ancestor::client[@id=''MDR'']''-->

for
<pallet>
<position row="0" bay="0" level="A">
<client id="HAL">
<partnum id="HA0132-1033 " isStock="N">HA0132-1033 </partnum>
<partnum id="HA9027EP " isStock="Y">HA9027EP </partnum>
</client>
<client id="MDR">
<partnum id="A/P FILES " isStock="N">A/P FILES </partnum>
</client>
<client id="OPS">
<partnum id="OPS " isStock="N">OPS
</partnum></client>
</position>
<position row="1" bay="1" level="B">
<client id="MDR">
<partnum id="A/P FILES " isStock="N">A/P FILES
</partnum>
</client>
</position>
<position row="1" bay="1" level="D">
<client id="MDR">
<partnum id="X-MAS DECORATION" isStock="N">X-MAS DECORATION
</partnum>
</client>
</pallet>

推荐答案




John Bailo写道:



John Bailo wrote:

示例,这些都不起作用:

节点://托盘/祖先::位置


<托盘>
< ; position row =" 0"托架= QUOT; 0" level =" A">
< client id =" HAL">
< partnum id =" HA0132-1033" isStock =" N"> HA0132-1033< / partnum>
< partnum id =" HA9027EP" isStock =" Y"> HA9027EP< / partnum>
< / client>
< client id =" MDR">
< partnum id =" A / P FILES isStock =" N"> A / P FILES< / partnum>
< / client>
< client id =" OPS">
< partnum id = OPS isStock =" N"> OPS
< / partnum>< / client>
< / position>
< position row =" 1"托架= QUOT 1 QUOT; level =" B">
< client id =" MDR">
< partnum id =" A / P FILES" isStock =" N"> A / P FILES
< / partnum>
< / client>
< / position>
< position row =" 1 QUOT;托架= QUOT 1 QUOT; level =" D">
< client id =" MDR">
< partnum id =" X-MAS DECORATION&qu​​ot; isStock =" N"> X-MAS装饰
< / partnum>
< / client>
< / pallet>
Examples, none of these work:

nodes://pallet/ancestor::position
<pallet>
<position row="0" bay="0" level="A">
<client id="HAL">
<partnum id="HA0132-1033 " isStock="N">HA0132-1033 </partnum>
<partnum id="HA9027EP " isStock="Y">HA9027EP </partnum>
</client>
<client id="MDR">
<partnum id="A/P FILES " isStock="N">A/P FILES </partnum>
</client>
<client id="OPS">
<partnum id="OPS " isStock="N">OPS
</partnum></client>
</position>
<position row="1" bay="1" level="B">
<client id="MDR">
<partnum id="A/P FILES " isStock="N">A/P FILES
</partnum>
</client>
</position>
<position row="1" bay="1" level="D">
<client id="MDR">
<partnum id="X-MAS DECORATION" isStock="N">X-MAS DECORATION
</partnum>
</client>
</pallet>



位置元素是托盘元素的子元素,所以我不会理解为什么你需要

//托盘/祖先:: position

如果你想访问位置元素,那么你需要

/托盘/位置

-


Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/


Martin Honnen写道:
Martin Honnen wrote:

位置元素是托盘元素的子元素所以我不喜欢't
理解你为什么要
//托盘/祖先::位置
如果你想访问位置元素那么你需要
/托盘/位置

The position elements are children of the pallet element so I don''t
understand why you want
//pallet/ancestor::position
If you want to access the position elements then you need
/pallet/position




所以,我想返回包含客户的所有POSITION节点,其中

id是M DR。


但我唯一想要的POSITION孩子是ID为MDR的客户。


如果我这样做


/托盘/位置/客户[@id =''MDR''] / ..


我获得所有职位,但所有职位都在这些职位上,而不仅仅是

客户的id =''MDR''

所以,从我的示例XML,如果我做了一个xpath来隔离@ id =' 'MBR'',我会像这样将
作为我的退货清单:


< pallet>

< position行= QUOT; 0"托架= QUOT; 0" level =" A">

< client id =" MDR">

< partnum id =" A / P FILES" isStock =" N"> A / P FILES< / partnum>

< / client>

< / position>

< position row =" 1"托架= QUOT 1 QUOT; level =" B">

< client id =" MDR">

< partnum id =" A / P FILES" isStock =" N" A / P FILES

< / partnum>

< / client>

< / position> ;

< position row =" 1"托架= QUOT 1 QUOT; level =" D">

< client id =" MDR">

< partnum id =" X-MAS DECORATION&qu​​ot; isStock =" N"> X-MAS装饰

< / partnum>

< / client>

< / pallet> ;


这就是为什么我以为我会使用祖先,找到所有的客户端节点,然后每个客户端节点的祖先是
(我认为这将排除每个位置节点的其他

子节点)。



So, I want to return all the POSITION nodes that contain CLIENTS whose
id is MDR.

But the only children of POSITION I want are the CLIENTS whose id is MDR.

If I do

/pallet/position/client[@id=''MDR'']/..

I get all the POSITIONS, but all CLIENTS in those positions, not just
CLIENTS whose id = ''MDR''

So, from my example XML, if I did an xpath to isolate @id=''MBR'', I would
like this to be my return list:

<pallet>
<position row="0" bay="0" level="A">
<client id="MDR">
<partnum id="A/P FILES " isStock="N">A/P FILES </partnum>
</client>
</position>
<position row="1" bay="1" level="B">
<client id="MDR">
<partnum id="A/P FILES " isStock="N">A/P FILES
</partnum>
</client>
</position>
<position row="1" bay="1" level="D">
<client id="MDR">
<partnum id="X-MAS DECORATION" isStock="N">X-MAS DECORATION
</partnum>
</client>
</pallet>

That''s why I thought I''d use ancestor, to find all the clientnodes, and
then each client node''s ancestor (which I think will exclude the other
child nodes of each position node).


看起来你想要使用descendant ::而不是祖先::


-

Greg Collins [微软MVP]

访问Brain Trove( http://www.BrainTrove.com
It looks like you are wanting to use descendant:: rather than ancestor::

--
Greg Collins [Microsoft MVP]
Visit Brain Trove ( http://www.BrainTrove.com )


这篇关于祖先:: XML语法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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