Solved

MSXML2.DOMDocument Parser Question

Posted on 2004-04-16
3
585 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
  • 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
Problem to be resolved in this article Currently, development of website and web application can be done without writing thousands of lines of programming code by hand. Description This can be done through by using a open source framework such …
The viewer will learn how to dynamically set the form action using jQuery.
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…

708 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

13 Experts available now in Live!

Get 1:1 Help Now