Link to home
Start Free TrialLog in
Avatar of Clif
ClifFlag for United States of America

asked on

XML Nodes (with VB6)

Ok, I'm having problems with trying to retrieve the nodes from an XML string.  For some reason I am not getting anything assigned to the nodes object.  The loadXML works without failure.

Below is my code, and at the bottom is an example (as best I could) of the XML string.

----- Code -----
    cXML.loadXML sXML
   
    Set objXMLNodeList = cXML.documentElement.selectNodes("opt")
    'I have also tried the following:
    'Set objXMLNodeList = cXML.documentElement.selectNodes("\\FVR\AO\opt\*")

    For Each objNode In objXMLNodeList
        Debug.Print objNode.Text
    Next

----- End of Code -----

----- XML String -----
<?xml version="1.0" encoding="UTF-8" ?>
<p784:FVR xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:p784="http://xx.xxxxxxxx.xxx/xxxx/xxxxxxxx/1111111">
<p537:AO xmlns:p537="http://xx.xxxxxxxx.xxx/xxxx/xxxxx/2222222">
<p537:attribute xsi:nil="true" />
<p537:opt>
<p537:id>1</p537:id>
<p537:desc>1994</p537:desc>
</p537:opt>
<p537:opt>
<p537:id>2</p537:id>
<p537:desc>1995</p537:desc>
</p537:opt>
<p537:opt>
<p537:id>3</p537:id>
<p537:desc>1996</p537:desc>
</p537:opt>
</p537:AO>
<ns2:vvvvvvv xmlns:ns2="http://xx.xxxxxxxx.xxx/xxxx/xxxxx/3333333" xmlns:ns1="http://xx.xxxxxxxx.xxx/xxxx/xxxxxxxx/444444444444444">
<nwyr>0</nwyr>
</ns2:vvvvvvv>
</p784:FVR>
----- End of XML String -----
Avatar of Clif
Clif
Flag of United States of America image

ASKER

Oh, I guess I should add the declarations for the XML objects...


    Dim cXML As New MSXML2.DOMDocument40

    Dim objXMLNodeList As MSXML2.IXMLDOMNodeList
    Dim objNode As MSXML2.IXMLDOMNode
Try this:
Set objXMLNodeList = cXML.getElementsByTagName("opt")
OR
Set objXMLNodeList = cXML.documentElement.selectNodes("//FVR/AO/opt")
Avatar of Clif

ASKER

Sorry for taking so long to reply.

Neither of the two suggestions worked.

I must say that I have never seen tags (with colons) like this:

<p784:FVR>
or
<p537:opt>

I'm wondering if that's part (or a source) of my problems.
ASKER CERTIFIED SOLUTION
Avatar of Weiping Du
Weiping Du
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Clif

ASKER

That was perfect!

Thanks.