Xml 使用命名空间属性和SelectSingleNode属性的XPATH

Xml 使用命名空间属性和SelectSingleNode属性的XPATH,xml,excel,xpath,namespaces,vba,Xml,Excel,Xpath,Namespaces,Vba,我得到了这个XML—它是Excel Ribbon的_rels文件: <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships"> <Relationship Id="rId3" Type="http://schemas.openxmlformats.

我得到了这个XML—它是Excel Ribbon的_rels文件:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Id="rId3" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/extended-properties" Target="docProps/app.xml"/>
<Relationship Id="rId2" Type="http://schemas.openxmlformats.org/package/2006/relationships/metadata/core-properties" Target="docProps/core.xml"/>
<Relationship Id="rId1" Type="http://schemas.openxmlformats.org/officeDocument/2006/relationships/officeDocument" Target="xl/workbook.xml"/>
<Relationship Id="cuID14" Type="http://schemas.microsoft.com/office/2007/relationships/ui/extensibility" Target="customUI/customUI14.xml"/>
</Relationships>

我发现了很多示例,但没有任何示例使用具有定义名称空间的属性。我尝试过类似于
oXMLDoc.SelectSingleNode(“//rels:Relationship[@rels:Type='http:

您的第二次尝试非常成功

而不是

//rels:Relationship[@rels:Type='http:...`
你应该使用

//rels:Relationship[@Type='http:...
因为属性不属于默认名称空间——只属于元素

另请参见:


谢谢!我敢发誓这是我第一次尝试。这是我在拜占庭路线上走到这一步的明显选择(XML/XPATH编码新手:-)。然而,现在它起作用了,我可以在这个兔子洞之前完成我想做的任何事情。非常感谢!
//rels:Relationship[@Type='http:...