Solved

Access data in XML file using MSXML2.DOMDocument

Posted on 2015-01-26
5
176 Views
Last Modified: 2016-02-26
I have a document formatted like this:

<TestResult xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<TestName>1234</TestName>
<TestID>P1</TestID>
<Score>70</Score>
<Learner>
<ID>5846</ID>
<Name>Fred Smith</Name>
</Learner>
</TestResult>



I'm loading it as follows:

    Set objXMLHttp = CreateObject("MSXML2.ServerXMLHTTP.6.0")
    objXMLHttp.Open "GET", strURL, False
    objXMLHttp.send
   
' This works but strReturn is formatted using { and : characters not as xml/soap
    strReturn = objXMLHttp.responseText
   
    Set xmlDoc = CreateObject("MSXML2.DOMDocument")
    xmlDoc.async = False
    xmlDoc.LoadXML strReturn

xmldoc as a Parse error, invalid at top level of document

How do I access the score and learner id ?
0
Comment
Question by:ASPDaddy
  • 4
5 Comments
 

Author Comment

by:ASPDaddy
ID: 40571340
I solved the parse error by setting the content type to XML, it was defaulting to JSON. The doc now looks loaded ok so I just need to know the syntax to access specif elements in the test and candidate.  The example is a single record but I like to know how to access using a loop as well in case we make files with more records. Thanks
0
 
LVL 23

Expert Comment

by:JSRWilson
ID: 40573159
0
 

Accepted Solution

by:
ASPDaddy earned 0 total points
ID: 40573176
Thanks

I had a look at that yesterday , its generic code for traversing a structure rather than specific access to known elements.

I figured it eventually by trial an error though :)

- For top level test data
xmlDoc.getElementsByTagName("TestName")(0).Text

- for data in the Learner record
xmlDoc.getElementsByTagName("Learner/Name")(0).Text
0
 

Author Comment

by:ASPDaddy
ID: 40573179
solved
0
 

Author Closing Comment

by:ASPDaddy
ID: 40582246
actual code
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
XML Data Missing in PHP SimpleXML 8 44
Automate switch config backup 3 45
File download script VBSCRIPT fail on download PPT files 2 32
Advice in Xamarin 21 47
This is an explanation of a simple data model to help parse a JSON feed
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

932 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

9 Experts available now in Live!

Get 1:1 Help Now