Xml XPath。从其他属性中提取属性值
您能否澄清一下,是否可以通过XPath请求其他属性来提取属性的值 例如:Xml XPath。从其他属性中提取属性值,xml,xpath,Xml,Xpath,您能否澄清一下,是否可以通过XPath请求其他属性来提取属性的值 例如: <Attributes> <Attribute> <Id>5</Id> <Value>56757364</Value> </Attribute> </Attributes> <Attributes> <Attribute> <Id>6</Id> &l
<Attributes>
<Attribute>
<Id>5</Id>
<Value>56757364</Value>
</Attribute>
</Attributes>
<Attributes>
<Attribute>
<Id>6</Id>
<Value>23372670</Value>
</Attribute>
</Attributes>
因为我的XML文件包含许多具有不同属性顺序的属性。这一个应该可以:
/Attributes/Attribute[Id=6]/Value
或者如果需要保留属性
节点结构
/Attributes/Attribute/Id[.=6]/following-sibling::Value
这些是元素,而不是属性,尽管名称为“属性”。请再问一个问题。如果我有两个或多个属性,我应该使用它们的编号:
/Attributes/Attribute[2]/Id[.=6]/following sibling::Value
有什么办法可以避免吗?我只需要使用Id。@ruhagen,如果Id值(6
)是唯一的,您不需要指定索引:/Attributes/Attribute/Id[.=6]/以下同级::value
仍然应该是足够的,谢谢。我将测试它
/Attributes/Attribute/Id[.=6]/following-sibling::Value