xpath查询具有相同名称的属性值

时间:2017-05-05 05:36:16

标签: xpath xml-attribute

嘿伙计我想知道获取具有特定名称的所有属性值所需的xpath:我需要属性的值" 代码": 例如:

<nsIdentiftcustBuss:BusinessAddress>
<nsCommon:AddressType
   code="12">TRADING</nsTCVCommon:AddressType>
  <nsCommon:AddressLine1>SAN SUI HOUSE</nsCommon:AddressLine1>
  <nsCommon:AddressLine2>KHARADI</nsCommon:AddressLine2>
  <nsCommon:AddressLine3>KALYANI NAGAR</nsCommon:AddressLine3>
  <nsCommon:AddressLine4>QUADRON</nsCommon:AddressLine4>
  <nsCommon:City>NEW YORK</nsCommon:City>
  <nsCommon:ZipPostalCode>GDU 87H</nsCommon:ZipPostalCode>
  <nsCommon:Country
   code="76">UNITED KINGDOM</nsCommon:Country>
 </nsIdentiftcustBuss:BusinessAddress>
 <nsIdentiftcustBuss:BusinessAddress>
  <nsCommon:AddressType
   code="11">REGISTERED</nsCommon:AddressType>
  <ns:AddressLine1>104,parkways</nsCommon:AddressLine1>
  <nsCommon:AddressLine2>lincoln street</nsCommon:AddressLine2>
  <nsCommon:AddressLine3>63 avenue</nsCommon:AddressLine3>
  <nsCommon:AddressLine4>manhattan</nsCommon:AddressLine4>
  <nsCommon:City>Northampton</nsCommon:City>
  <nsCommon:ZipPostalCode>NNS 47L</nsCommon:ZipPostalCode>
  <nsCommon:Country
   code="76">UNITED KINGDOM</nsCommon:Country>
 </nsIdentiftcustBuss:BusinessAddress>

我需要两个节点的属性名称国家代码的输出 这是我使用的xpath

/*:BusinessAddress/*:Country/(@code)

我得到的输出为

 code, 76
 code, 76

但我只需要值:

 76
 76

1 个答案:

答案 0 :(得分:0)

尝试使用括号 @coade

例如: -

/*:BusinessAddress/*:Country/@code