HI
I am having a problem with 'selectSingleNode' method.
It is not finding the node and i have no idea what am i doing wrong. It didn't work with my original code - i had a look on the net and found the below simple example from which i copied code and pasted xml content to my xml file but it still doesn't work!!!! I have set up a reference to MSXML v4.0 in tools.
Can anyone help ?
the bug must be somewhere in this line :
Set oXMLNode = oXMLDoc.selectSingleNode("//EXAMPLE/CUSTOMER[@id='1' and @type='B']")
Please find below xml file and vba code.
xml file:
---------------------------------------------------------
<?xml version='1.0'?>
<EXAMPLE>
<CUSTOMER id="1" type="B">Mr. Jones</CUSTOMER>
<CUSTOMER id="2" type="C">Mr. Johnson</CUSTOMER>
</EXAMPLE>
code:
------------------------------------------------------------
Sub GetSingleValue()
Dim oXMLDoc As DOMDocument
Dim oXMLNode As IXMLDOMNode
Set oXMLDoc = New DOMDocument
oXMLDoc.LoadXML (Range("XML_Path").value)'checked it's ok
Set oXMLNode = oXMLDoc.selectSingleNode("//EXAMPLE/CUSTOMER[@id='2' or @type='C']")
MsgBox oXMLNode.Text 'will show "Mr Johnson"
Set oXMLNode = oXMLDoc.selectSingleNode("//EXAMPLE/CUSTOMER[@id='1' and @type='B']")
MsgBox oXMLNode.Text 'will show "Mr Jones"
MsgBox oXMLNode.Attributes.getNamedItem("id").Text 'will show "1"
End Sub
thank you
I am having a problem with 'selectSingleNode' method.
It is not finding the node and i have no idea what am i doing wrong. It didn't work with my original code - i had a look on the net and found the below simple example from which i copied code and pasted xml content to my xml file but it still doesn't work!!!! I have set up a reference to MSXML v4.0 in tools.
Can anyone help ?
the bug must be somewhere in this line :
Set oXMLNode = oXMLDoc.selectSingleNode("//EXAMPLE/CUSTOMER[@id='1' and @type='B']")
Please find below xml file and vba code.
xml file:
---------------------------------------------------------
<?xml version='1.0'?>
<EXAMPLE>
<CUSTOMER id="1" type="B">Mr. Jones</CUSTOMER>
<CUSTOMER id="2" type="C">Mr. Johnson</CUSTOMER>
</EXAMPLE>
code:
------------------------------------------------------------
Sub GetSingleValue()
Dim oXMLDoc As DOMDocument
Dim oXMLNode As IXMLDOMNode
Set oXMLDoc = New DOMDocument
oXMLDoc.LoadXML (Range("XML_Path").value)'checked it's ok
Set oXMLNode = oXMLDoc.selectSingleNode("//EXAMPLE/CUSTOMER[@id='2' or @type='C']")
MsgBox oXMLNode.Text 'will show "Mr Johnson"
Set oXMLNode = oXMLDoc.selectSingleNode("//EXAMPLE/CUSTOMER[@id='1' and @type='B']")
MsgBox oXMLNode.Text 'will show "Mr Jones"
MsgBox oXMLNode.Attributes.getNamedItem("id").Text 'will show "1"
End Sub
thank you