Extracting data from xml using vb 6

Posted on 2011-05-03
Last Modified: 2012-05-11
I have a 2 part problem.  I have an application that needs to get data from an xml document that is loaded.  The document is in the format shown below.  

Problem 1:  I need to get all of the info from the document between <Islands> and </Islands>.  I'm trying the following but am receiving an error on compile: Invalid use of property

    Dim xmlPSIDGroup As IXMLDOMNodeList
    xmlPSIDGroup = xmlRequest.selectNodes("Form/Islands/PSIDGroup")

Problem 2: Once I have the informaiton, I need to add it to another xml document so it looks like document 2 shown below.

Any help would be greatly appreciated.  I am on a tight deadline and am spinning my wheels right now.
Document 1

Document 2
<ValidationErrors><row><Error>Error message</Error></row><row><Error>Next Error</Error></row></ValidationErrors><Recordsets>><PSIDGroup><prsvalue>Test</prsvalue><id>0</id><insertflag>T</insertflag></PSIDGroup><Assigned><row><id>1</id><insertflag>F</insertflag></row></Assigned><Unassigned><row><id>2</id><insertflag>T</insertflag></row><row><id>3</id><insertflag>T</insertflag></row></Unassigned></Recordsets>

Open in new window

Question by:dyarosh
    LVL 16

    Accepted Solution

    You don't indicate what the object "xmlRequest" is.
    The only xml work I've done used a Node object to do a selectNodes.
    For example, to get everything within the PSIDGroup, I would do the following...

    Dim Doc as MSXML2.DOMDocument40
    Dim FormNode as MSXML2.IXMLDOMElement
    Dim IslandsNode as MSXML2.IXMLDOMElement
    Dim PSIDNodes as MSXML2.IXMKDOMNodeList
    Doc.Load("Document 1")
    Set FormNode = Doc.DocumentElement  'Root Node
    Set IslandNode = FormNode.selectSingleNode("./Islands")
    Set PSIDNodes as IslandNode.selectNodes(./PSIDGroup)

    This can likely be short-cutted with something like

    Doc.Load("Document 1")
    Set PSIDNodes = Doc.DocumentElement.selectNodes(./Form/Islands/PSIDGroup)

    But that would get all PSIDGroup nodes that might be embedded in multiple Islands ndoes.

    From there, you can continue to get individual nodes within an node object, or list of nodes within a node object.  Then you need a Doc2 object for Document 2, get a reference to the node where you want to insert other node objects into, and use the command "insertBefore" to copy a node to the new document.

    Author Comment

    Request is defined as follows:

    Dim xmlRequest As FreeThreadedDOMDocument40

    Author Comment

    I changed the xmlPSIDGroup definition to the following  :Dim xmlPSIDGroup As DOMDocument

    object variable or with block variable not set

    Author Closing Comment

    I found what caused my error.  I forgot to use SET.  Thanks for your help.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Introduction While answering a recent question ( in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
    Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    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…

    760 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

    Need Help in Real-Time?

    Connect with top rated Experts

    7 Experts available now in Live!

    Get 1:1 Help Now