Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

MSXML2.DOMDocument Parser Question

Posted on 2004-04-16
3
Medium Priority
?
631 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 2000 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

When crafting your “Why Us” page, there are a plethora of pitfalls to avoid. Follow these five tips, and you’ll be well on your way to creating an effective page.
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…
This video teaches users how to migrate an existing Wordpress website to a new domain.
The viewer will get a basic understanding of what section 508 compliance can entail, learn about skip navigation links, alt text, transcripts, and font size controls.
Suggested Courses

824 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