嗨,我只想獲取值爲「123abc」的元素A。我已經嘗試過但都失敗了。如何選擇具有特定值的grand-grandchild節點的節點
// Package/A [A/B/C /。 = 123ABC]
//封裝/ A [含有(A/B/C,123ABC)]
我希望它返回此:
<A>
<System mtm="8742" os="Windows XP" oslang="en" />
<System mtm="2055" os="Windows XP" oslang="jp" />
<A>
<B>
<C>123abc</C>
<C>789</C>
<C>567</C>
</B>
</A>
</A>
示例XML到查詢上運行:
<?xml version="1.0" encoding="UTF-8"?>
<Database version="300">
<Package>
<A>
<System mtm="8742" os="Windows XP" oslang="en" />
<System mtm="2055" os="Windows XP" oslang="jp" />
<A>
<B>
<C>123abc</C>
<C>789</C>
<C>567</C>
</B>
</A>
</A>
</Package>
<Package>
<A>
<System mtm="8742" os="Windows XP" oslang="en" />
<System mtm="2055" os="Windows XP" oslang="jp" />
<A>
<B>
<C>efg123</C>
<C>789</C>
<C>567</C>
</B>
</A>
</A>
</Package>
</Database>
你可以在這裏測試答案:http://www.freeformatter.com/xpath-tester.html#ad-output
添加了我正在嘗試處理的實際xml,但無法工作,它可能是特殊字符轉義?
我試圖處理實際XML如下,我試圖
// TableSection/SectionItem [SectionItem /小區/。 = 「00-18-E7-17-48-64」]
// TableSection/SectionItem [含有(SectionItem /細胞, 「00-18-E7-17-48-64」)]
<TableSection name="SNMP Devices" IsTreeFormat="true">
<SectionProperties>
<Column id="1" Name="IP Address" />
<Column id="2" Name="Description" />
</SectionProperties>
<SectionItem>
<Cell columnid="1">
192.168.99.54
</Cell>
<Cell columnid="2">
WMI XScan
</Cell>
<SectionItem>
<Cell columnid="1">
ScanType
</Cell>
<Cell columnid="2">
WMIScan
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
Device description
</Cell>
<Cell columnid="2">
WMI dscription
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
MACAddress
</Cell>
<Cell columnid="2">
00-18-E7-17-48-64
</Cell>
</SectionItem>
</SectionItem>
<SectionItem>
<Cell columnid="1">
192.168.99.55
</Cell>
<Cell columnid="2">
WMI XScan
</Cell>
<SectionItem>
<Cell columnid="1">
ScanType
</Cell>
<Cell columnid="2">
WMIScan
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
Device description
</Cell>
<Cell columnid="2">
WMI dscription
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
MACAddress
</Cell>
<Cell columnid="2">
90-2B-34-64-16-9D
</Cell>
</SectionItem>
</SectionItem>
<SectionItem>
<Cell columnid="1">
192.168.99.107
</Cell>
<Cell columnid="2">
VMWare : "navvms08.Crest.local"
</Cell>
<SectionItem>
<Cell columnid="1">
MACAddress
</Cell>
<Cell columnid="2">
00-07-E9-0D-05-C5
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
Device identifier
</Cell>
<Cell columnid="2">
1.3.6.1.4.1.6876.4.1
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
Device name
</Cell>
<Cell columnid="2">
"navvms08.Crest.local"
</Cell>
</SectionItem>
<SectionItem>
<Cell columnid="1">
Device description
</Cell>
<Cell columnid="2">
"VMware ESXi 5.5.0 build-1623387 VMware, Inc. x86_64"
</Cell>
</SectionItem>
</SectionItem>
</TableSection>
謝謝保羅。我已經添加了我正在嘗試處理的原始問題的實際XML,因爲我仍然無法使查詢生效。非常感謝任何人都可以爲我解決這個問題,因爲我在這方面花了很多時間。 – Terry 2014-10-17 03:36:44