Solved

MSXML2.DOMDocument Parser Question

Posted on 2004-04-16
3
609 Views
Last Modified: 2010-05-18
I am relatively new to XML and I have installed SQLXML on my sql web server.  I have got it to return the results of a query in xml format.  I need to then take the results and loop through them to display them in a manner I want.  Here is the xml that is returned.  I want to loop through each row and put the value of QTR in a variable and Start_Date into a variable and End_Date into a variable.  Process them and loop to the next row.  I am using MSXML2.DOMDocument to parse the XML any help with VB code would be appreciated.  Thanks

  <?xml version="1.0" encoding="utf-8" ?>
- <root>
  <qtr_detail QTR="2003-Q1" Start_Date="2002-12-29T00:00:00" End_Date="2003-03-29T00:00:00" />
  <qtr_detail QTR="2003-Q2" Start_Date="2003-03-30T00:00:00" End_Date="2003-06-28T00:00:00" />
  <qtr_detail QTR="2003-Q3" Start_Date="2003-06-29T00:00:00" End_Date="2003-09-27T00:00:00" />
  <qtr_detail QTR="2003-Q4" Start_Date="2003-09-28T00:00:00" End_Date="2004-01-03T00:00:00" />
  <qtr_detail QTR="2004-Q1" Start_Date="2004-01-04T00:00:00" End_Date="2004-04-03T00:00:00" />
  <qtr_detail QTR="2004-Q2" Start_Date="2004-04-04T00:00:00" End_Date="2004-07-03T00:00:00" />
  <qtr_detail QTR="2004-Q3" Start_Date="2004-07-04T00:00:00" End_Date="2004-10-02T00:00:00" />
  <qtr_detail QTR="2004-Q4" Start_Date="2004-10-03T00:00:00" End_Date="2005-01-01T00:00:00" />
  <qtr_detail QTR="2005-Q1" Start_Date="2005-01-02T00:00:00" End_Date="2005-04-02T00:00:00" />
  <qtr_detail QTR="2005-Q2" Start_Date="2005-04-03T00:00:00" End_Date="2005-07-02T00:00:00" />
  <qtr_detail QTR="2005-Q3" Start_Date="2005-07-03T00:00:00" End_Date="2005-10-01T00:00:00" />
  <qtr_detail QTR="2005-Q4" Start_Date="2005-10-02T00:00:00" End_Date="2005-12-31T00:00:00" />
  <qtr_detail QTR="2006-Q1" Start_Date="2006-01-01T00:00:00" End_Date="2006-04-01T00:00:00" />
  <qtr_detail QTR="2006-Q2" Start_Date="2006-04-02T00:00:00" End_Date="2006-07-01T00:00:00" />
  <qtr_detail QTR="2006-Q3" Start_Date="2006-07-02T00:00:00" End_Date="2006-09-30T00:00:00" />
  <qtr_detail QTR="2006-Q4" Start_Date="2006-10-01T00:00:00" End_Date="2006-12-30T00:00:00" />
  <qtr_detail QTR="2007-Q1" Start_Date="2006-12-31T00:00:00" End_Date="2007-03-31T00:00:00" />
  <qtr_detail QTR="2007-Q2" Start_Date="2007-04-01T00:00:00" End_Date="2007-06-30T00:00:00" />
  <qtr_detail QTR="2007-Q3" Start_Date="2007-07-01T00:00:00" End_Date="2007-09-29T00:00:00" />
  <qtr_detail QTR="2007-Q4" Start_Date="2007-09-30T00:00:00" End_Date="2007-12-29T00:00:00" />
  </root>
0
Comment
Question by:wilnah
[X]
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
  • 2
3 Comments
 
LVL 8

Expert Comment

by:plq
ID: 10845227
set a reference in your project to the DOM

then try this...

dim doc as new DomDocument
dim nod as IXMLDOMNode

for each nod in doc.childNodes(0)
  msgbox nod.nodeName & " " & nod.attributes.getNamedItem("QTR").text
next

sorry I didn't test it
0
 

Author Comment

by:wilnah
ID: 10845293
Sorry to sound dumb but this is the code I have to set the dom object .  I get an error object does not support this property or method.  Thanks for your help.

Dim xmlHttp
Set xmlHttp = CreateObject("Msxml2.XMLHTTP")
sql = "http://localhost/sqlxml?SQL=SELECT+*+FROM+qtr_detail+FOR+XML+AUTO&root=root"
xmlHttp.Open "Get", sql, False
xmlHttp.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xmlHttp.Send
Dim doc As New DOMDocument
Dim nod As IXMLDOMNode
doc.loadXML xmlHttp.responsetext
 
For Each nod In doc.childNodes(0) 'THIS IS WHERE THE ERROR POPS'
      MsgBox nod.nodeName & " " & nod.Attributes.getNamedItem("QTR").Text
Next
0
 
LVL 8

Accepted Solution

by:
plq earned 500 total points
ID: 10845311
ooops. Well I did say I didn't test it !!!

It should have been...

For Each nod In doc.childNodes(0).childNodes

a step close anyway
0

Featured Post

Report: Liquid Web beats Amazon, Rackspace & More

A study by performance analyst firm Cloud Spectator finds that Liquid Web beats rivals Amazon, Rackspace and DigitalOcean when it comes to website and cloud application performance.

Question has a verified solution.

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

Get to know the ins and outs of building a web-based ERP system for your enterprise. Development timeline, technology, and costs outlined.
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

734 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