[Last Call] Learn how to a build a cloud-first strategyRegister Now


Extracting data from xml using vb 6

Posted on 2011-05-03
Medium Priority
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
  • 3
LVL 16

Accepted Solution

HooKooDooKu earned 2000 total points
ID: 35517082
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
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

ID: 35517170
Request is defined as follows:

Dim xmlRequest As FreeThreadedDOMDocument40

Author Comment

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

object variable or with block variable not set

Author Closing Comment

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

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses
Course of the Month18 days, 11 hours left to enroll

834 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