XML Nodes (with VB6)

Posted on 2007-03-23
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

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

----- XML String -----
<?xml version="1.0" encoding="UTF-8" ?>
<p784:FVR xmlns:xsi="" xmlns:xsd="" xmlns:soapenc="" xmlns:soapenv="" xmlns:p784="">
<p537:AO xmlns:p537="">
<p537:attribute xsi:nil="true" />
<ns2:vvvvvvv xmlns:ns2="" xmlns:ns1="">
----- End of XML String -----
Question by:Clif
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
LVL 10

Author Comment

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

Expert Comment

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

Author Comment

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:


I'm wondering if that's part (or a source) of my problems.

Accepted Solution

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.async= false;
set ns = "xmlns:na='' xmlns:nb=''";
cXML.setProperty("SelectionNamespaces", ns);
Set objXMLNodeList = cXML.selectNodes("//FVR/AO/opt")

- To check example in detail:
LVL 10

Author Comment

ID: 18810598
That was perfect!


Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
Suggested Courses
Course of the Month8 days, 9 hours left to enroll

615 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