You are viewing a plain text version of this content. The canonical link for it is here.
Posted to c-dev@xerces.apache.org by "Jones, Brian O." <bo...@ngc.com> on 2004/07/21 16:03:02 UTC

newbie trying to parse xml file

Hello,

I am trying to parse my xml file but having trouble getting correct values return if you can offer any insight that would be great.
I want to be able to get out the values of my table the same as my type.

code
------
DomDocument *doc = parser->getDocument();

DomNodeList *nl = doc->getElementsByTagName(XMLString::transcode("myType");
//This should get me to the point of the type that I want

DomNode *type = nl->item(0);

for(DomNode *data = type->getFirstChild();
      data != 0;
     data = data->getNextSibling())
{
  name = XMLString::transcode(data->getNodeName());
  value = XMLString::transcode(data->getTextContent());
  cout << name << value << endl;
}

DomNodeList *ml = doc->getElementsByTagName(XMLString::transcode("myTableEntry");
//This should get me to the point of the type that I want

DomNode *mtype = ml->item(0);

for(DomNode *mdata = mtype->getFirstChild();
      mdata != 0;
     mdata = mdata->getNextSibling())
{
  mname = XMLString::transcode(mdata->getNodeName());
  mvalue = XMLString::transcode(mdata->getTextContent());
  cout << mname << mvalue << endl;
}



xml
-----

<?xml version="1.0"?>
<myLib>
  <ID>123</ID>
  <Entries>2</Entries>
  <myEntries>
     <myType>
       <one>Hello</one>
       <two>World</two>
       <numTbl>2</numTbl>
       <myTable>
         <myTableEntry>
            <three>Stop</three>
            <four>Fighting</four>
         </myTableEntry>
         <myTableEntry>
            <five>Right</five>
            <six>Now</six>
         </myTableEntry>
       </myTable>
     </myType>
     <myType>
       <one>Hello</one>
       <two>World</two>
       <numTbl>2</numTbl>
       <myTable>
         <myTableEntry>
            <three>Stop</three>
            <four>Fighting</four>
         </myTableEntry>
         <myTableEntry>
            <five>Stop</five>
            <six>Fighting</six>
         </myTableEntry>
       </myTable>
     </myType>
   </myEntries>
</myLib>
  

Output
---------

one Hello
#text

two World!
#text

numTbl 2
#text

myTable
     
	Stop
	Fighting
	Right
	Now

one Hello
#text

two World!
#text

numTbl 2
#text

myTable
     
	Stop
	Fighting
	Right
	Now

Thanks in Advance...


Brian Jones
Senior Software Engineer
(Email) bo.jones@ngc.com
Phone (410) 993-2072
Fax (410) 981-8381




---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-c-dev-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-c-dev-help@xml.apache.org