Solved

XML Nodes (with VB6)

Posted on 2007-03-23
5
1,024 Views
Last Modified: 2010-08-05
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 -----
0
Comment
Question by:Clif
  • 3
  • 2
5 Comments
 
LVL 10

Author Comment

by:Clif
ID: 18782635
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
0
 
LVL 9

Expert Comment

by:owenli27
ID: 18784174
Try this:
Set objXMLNodeList = cXML.getElementsByTagName("opt")
OR
Set objXMLNodeList = cXML.documentElement.selectNodes("//FVR/AO/opt")
0
 
LVL 10

Author Comment

by:Clif
ID: 18808098
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.
0
 
LVL 9

Accepted Solution

by:
owenli27 earned 500 total points
ID: 18809389
It is also my first time see this. You need  to set SelectionNamespaces Property,. It should be somethings like this:

cXML.loadXML sXML
cXML.async= false;
set ns = "xmlns:na='http://xx.xxxxxxxx.xxx/xxxx/xxxxxxxx/1111111' xmlns:nb='http://xx.xxxxxxxx.xxx/xxxx/xxxxx/2222222'";
cXML.setProperty("SelectionNamespaces", ns);
Set objXMLNodeList = cXML.selectNodes("//FVR/AO/opt")

- To check example in detail:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/html/36b6439d-e4e0-42d3-baf5-6c24e17c9ed9.asp
0
 
LVL 10

Author Comment

by:Clif
ID: 18810598
That was perfect!

Thanks.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Getting warning: You are about to delete 1 row(s) 9 48
XML to SQL Table using c# 5 64
fso.FolderExists("\\server\HiddenFolder$") 4 65
XSLT Display Label Name 1 22
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

778 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question