Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

MSXML2.DOMDocument Parser Question

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

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

Because your company can’t afford for you to make SEO mistakes, you’ll want to ensure you’re taking the right steps each and every time you post a new piece of content. This list of optimization do’s and don’ts can help you become an SEO wizard.
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
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…
Suggested Courses

719 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