我的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