我有一个指定的XML文档(结构不能更改),想要获取写在节点上方的注释。该文档如下:
<!--Some comment here-->
<attribute name="Title">Book A</attribute>
<attribute name="Author">
<value>Joe Doe</value>
<value>John Miller</value>
</attribute>
<!--Some comment here-->
<attribute name="Code">1</attribute>
因此,注释是可选的,但如果有注释,我希望在每个属性上方获取注释。 使用
/ * / comment()[n]
会给我第n个注释,但对于n = 2,我自然会得到第三个属性的注释,因此属性和注释之间没有连接。 有什么想法?谢谢