I've got this XML - it's an Excel Ribbon's _rels file:
<?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>
I'm trying to use SelectSingleNode
to check if the last Relationship element exists, the one with an ID of "cuID14", by checking its Type
attribute. I have code that works if the Relationships element doesn't have the xmlns attribute, i.e., if I change the second line to just Relationships>
. I'm trying to do it right though and just can't get the syntax to work. Here's my code with the SelectSingleNode
function that works without the xmlns complication:
Sub CheckForAttribute()
Dim oXMLDoc As MSXML2.DOMDocument60
Dim oXMLElement As MSXML2.IXMLDOMElement
Dim XmlRelsNamespace As String
XmlRelsNamespace = "xmlns:rels='http://schemas.openxmlformats.org/package/2006/relationships'"
Set oXMLDoc = New MSXML2.DOMDocument60
oXMLDoc.SetProperty "SelectionNamespaces", XmlRelsNamespace
oXMLDoc.Load "C:\Users\doug\XPATH_TESTER.xml"
'The following line works if the Relationships element to just <Relationships>
Set oXMLElement = oXMLDoc.SelectSingleNode("//Relationship[@Type='http://schemas.microsoft.com/office/2007/relationships/ui/extensibility']")
End Sub
I've found lots of examples but nothing that uses the attributes with a defined namespace. I've tried things like oXMLDoc.SelectSingleNode("//rels:Relationship[@rels:Type='http:
...