我想在我的XML中找到基于AddressID的邮政编码。
<Address City="Londong" County="Greater London" FlatNumber="" HouseNumber="702" PostCode="EH14 3HW" Street="" AddressID="0" isPrimary="1"/>
<Address City="Braintree" County="Essex" FlatNumber="" HouseNumber="586" PostCode="CM79AB" Street="Blocking End" AddressID="1" isPrimary="0"/>
我正在尝试不同的XPath语句,而不是获取值或获取null。我想说,给我一个AddressID = 1的PostCode。
我尝试了以下内容:
//Address[AddressID = 1]@PostCode
//Address[AddressID = 1]/@PostCode
//Address[AddressID = 1 @PostCode]
答案 0 :(得分:1)
您的AddressID是一个属性(与PostCode相同),因此您需要使用@
。
//Address[@AddressID="1"]/@PostCode
您正在尝试的查询//Address[AddressID = 1]/@PostCode
,查找类似的内容:
<Address PostCode="ABC"> <!-- PostCode is an attribute (has an @) -->
<AddressID>1</AddressID> <!-- AddressID is a child element (no @) -->
</Address>