Retrieving XML data

All questions regarding Windows programming, post here. API,COM, ActiveX, DirectX, OpenGL, MFC and so on...

Moderators: Darobat, RecursiveS, Dante Shamest, Bugdude, Wizard

Retrieving XML data

Postby gpsushil » Thu Feb 28, 2008 11:21 pm

IXMLDOMDocument class is used to load the XML file and it's working fine. But what I want do it get the elements from XML file and add it to list view control.

Using pXMLDom->get_text(&bstr);
I'm getting all the elements but i want them in tokens so that i can add them in list view.
gpsushil
 
Posts: 34
Joined: Thu Feb 21, 2008 2:59 am

Postby ventsyv » Fri Feb 29, 2008 11:34 am

Try XPath query. For more info on XPath : www.w3schools.com
Something like this should work:

Code: Select all
pXMLDom->SelectNodes("//myNode");
User avatar
ventsyv
 
Posts: 2810
Joined: Mon Sep 22, 2003 5:25 pm
Location: MD USA

Postby gpsushil » Mon Mar 03, 2008 5:48 am

I saw pSMLDom->SelectNodes("//myNode",pNodeList);

I couldnot get values for the individual node.

My XML looks like this:

Code: Select all
<?xml version="1.0" encoding="ISO-8859-1"?>
<CATALOG>
   <CD>
      <TITLE>Empire Burlesque</TITLE>
      <ARTIST>Bob Dylan</ARTIST>
      <COUNTRY>USA</COUNTRY>
      <COMPANY>Columbia</COMPANY>
      <PRICE>10.90</PRICE>
      <YEAR>1985</YEAR>
   </CD>
   <CD>
      <TITLE>Hide your heart</TITLE>
      <ARTIST>Bonnie Tyler</ARTIST>
      <COUNTRY>UK</COUNTRY>
      <COMPANY>CBS Records</COMPANY>
      <PRICE>9.90</PRICE>
      <YEAR>1988</YEAR>
   </CD>
   <CD>
      <TITLE>Hide your face</TITLE>
      <ARTIST>Bonnie Gupta</ARTIST>
      <COUNTRY>USA</COUNTRY>
      <COMPANY>MGM Records</COMPANY>
      <PRICE>19.90</PRICE>
      <YEAR>1998</YEAR>
   </CD>
</CATALOG>

From above XML file I want in one query TITLE of the book and next ARTIST and so on. How is it possible ?
gpsushil
 
Posts: 34
Joined: Thu Feb 21, 2008 2:59 am

Postby ventsyv » Fri Mar 07, 2008 11:54 am

Sure is.
Code: Select all
SelectNodes("//CD", pNodeList)
foreach (Node myNode in pNodelist)
{
   myNode->SelectSingleNode("//title", titleNode);
   myNode->SelectSingleNode("//artist", artistNode);

   titleNode.DoStuff();
   artistNode.DoStuff();
}
User avatar
ventsyv
 
Posts: 2810
Joined: Mon Sep 22, 2003 5:25 pm
Location: MD USA


Return to Windows Programming

Who is online

Users browsing this forum: No registered users and 2 guests