我的XML樹包含此結構中的XPath語法在路徑選擇具有多個屬性節點
<foo name="bar">
<location order="1">data1</location>
<location order="2">data2</location>
</foo>
我想是指任何地方的樹,其中位序=「2」(有可能是其中的1000)來操縱所有data2文本。我無法讓vba通過xpath字符串分配來識別它。
我嘗試過很多事情,但,使事情是很有道理的,在我看來
xPath = "//prefix:foo[@name='bar']/location[@order='2']"
但它確實承認XPATH分配給foo如果我刪除。
"/location[@order='2']"
我在xpath語法中做錯了什麼?還是有更多的分配一個路徑到一個包含多個屬性的節點來在樹結構中選擇?
也許我想使用錯誤的方法來訪問變量?
Dim list as IXMLDOMNodeList
Set list = xDoc.SelectNodes(xPath)
Debug.Print list.length
給了我一個0,但也有一些特定節點的兩個實例在我的XML
編輯: 仍然給了我零做一些事情與你的後。這裏有一個例子xml,所以你可以看到命名空間。如果我忽略「/ location [@ order ='2']」,我仍然可以打印出一個長度。另外要說明的是,我只對這條道路感興趣,即可能有許多其他foo節點與孩子在一起。這些我現在不在乎。
<?xml version="1.0" encoding="utf-8"?>
<IPSGDatas xsi:schemaLocation="uri:mybikes:wheels MYBIKES%20WHEELS%202012.xsd"
xmlns="uri:mybikes:wheels"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<header>
<language_id>120</language_id>
</header>
<datas>
<good>
<signature/>
<bike>
<foos>
<marker>
<location order="1">data1</location>
<location order="2">data2</location>
</marker>
<foo name="bar">
<location order="1">data1</location>
<location order="2">data2</location>
</foo>
</foos>
<profile_id>MyName1</profile_id>
</bike>
<action_id>New</action_id>
<index_id>1</index_id>
<agency/>
<agency_reference/>
<accreditation_id>U</accreditation_id>
</good>
<good>
<signature/>
<bike>
<foos>
<marker>
<location order="1">data1</location>
<location order="2">data2</location>
</marker>
<foo name="bar">
<location order="1">data1</location>
<location order="2">data2</location>
</foo>
</foos>
<profile_id>MyName2</profile_id>
</bike>
<action_id>New</action_id>
<index_id>1</index_id>
<agency/>
<agency_reference/>
<accreditation_id>U</accreditation_id>
</good>
</datas>
</IPSGDatas>
'」 foo [@ name ='bar']/location [@ order ='2']「'爲我工作 - 但您似乎沒有在您的示例XML中包含某些名稱空間,因此很難確定。你可以讓它更具代表性的實際使用情況? –
嗯。從我的手機上打字並在無法訪問的情況下使用筆記本電腦上的文件。給我一點,直到我做,我會看看我能做些什麼。目前,我可以告訴你,沒有位置順序=「2」節點,名稱空間工作得很好。 – Dan
:/也許我使用了錯誤的方法。 – Dan