2013-01-17 30 views
1

我想有一个xpath表达式来获得一个节点的所有即时和非叶儿童。Xpath表达式来获得即时和非叶儿童

当我运行这样的XML树的表达:

<root> 
<attribute1>a</attribute1> 
<attribute2>b</attribute2> 
<attribute3>c</attribute3> 
<ElementA> 
    <ElementB> 
     <ElementC>AC</ElementC> 
    </ElementB> 
</ElementA> 
<ElementX> 
    <ElementB1> 
     <ElementC1>C1</ElementC1> 
    </ElementB1> 
</ElementX> 
<Other> 
    <ElementB2>B2</ElementB2> 
</Other> 
<NewOne> 
    <ElementB3> 
     <ElementC3> 
      <ElementC4>C4</ElementC4> 
     </ElementC3> 
    </ElementB3> 
</NewOne> 
</root> 

我应该得到ElementA,ElementX,其他,NewOne。

Thans寻求帮助。

+0

你为什么标记此【JAVA]? – BoltClock

+0

这是一个错误:那是因为我使用java程序来浏览xml树。 – VRTHT

回答

4

这将是:

/root/*[*] 

(谓语是有,以确保选择的节点至少有一个孩子)

+0

嗨Fdreger,它绝对正常工作。万分感谢。 – VRTHT