Solved

MSXML2.DOMDocument Parser Question

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

Technology Partners: 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

Learn by example how to specify CSS selectors for Selenium WebDriver test automation software.
When it comes to security, close monitoring is a must. According to WhiteHat Security annual report, a substantial number of all web applications are vulnerable always. Monitis offers a new product - fully-featured Website security monitoring and pr…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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).

628 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