Hello,
I need some help with the DOM TreeWalker API.
I modified the Xerces DOMPrint sample because I wanted to play around
with the DOMTreeWalker API to iterate through the sample.xml file.
Unfortunately I can't get the treewalker to spit out anything ... it
seems others have had similar problems as well see:
http://groups.google.com/groups?hl=e....net&frame=off
Am I getting the wrong root node? How does one use the treewalker?
What am I doing wrong. Please advise,
//---Code Segment Begins Here---
// Some boilerplate omitted
gXmlFile = argV[parmInd];
//
// Create our parser, then attach an error handler to the parser.
// The parser will call back to methods of the ErrorHandler if it
// discovers errors during the course of parsing the XML
document.
//
XercesDOMParser *parser = new XercesDOMParser ;
parser->setValidationS cheme(gValSchem e);
parser->setDoNamespace s(gDoNamespaces );
parser->setDoSchema(gD oSchema);
parser->setValidationS chemaFullChecki ng(gSchemaFullC hecking);
parser->setCreateEntit yReferenceNodes (gDoCreate);
DOMTreeErrorRep orter *errReporter = new DOMTreeErrorRep orter();
parser->setErrorHandle r(errReporter);
// Parse the XML file, catching any XML exceptions that might
propogate
// out of it.
//
bool errorsOccured = false;
try
{
parser->parse(gXmlFile );
}
// More boilerplate omitted
DOMDocument *sensorml_doc = parser->getDocument( );
DOMElement *sensor_root = sensorml_doc->getDocumentEle ment();
DOMTreeWalker *walker =
sensorml_doc->createTreeWalk er(sensor_root,
DOMNodeFilter:: SHOW_ALL,
NULL, true);
DOMNode *current_node = NULL;
char* barf = NULL;
for (int ixml = 0; ixml < 5; ixml++)
{
std::cout << "Test NodeValue: " << barf << std::endl;
}
for (current_node = walker->getCurrentNode (); current_node != NULL
; current_node = walker->nextNode())
{
char *strValue = XMLString::tran scode(current_n ode->getNodeName()) ;
std::cout << "NodeValue: " << strValue << std::endl;
XMLString::rele ase(&strValue);
}
// Clean up the error handler. The parser does not adopt handlers
// since they could be many objects or one object installed for
multiple
// handlers.
//
delete errReporter;
//---Code Segment Ends Here---
<!-- XML BEGINS HERE -->
<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE personnel SYSTEM "personal.d td">
<personnel>
<person id="Big.Boss" >
<name><family>B oss</family> <given>Big</given></name>
<email>ch***@fo o.com</email>
<link subordinates="o ne.worker two.worker three.worker four.worker
five.worker"/>
</person>
<person id="one.worker" >
<name><family>W orker</family> <given>One</given></name>
<email>on*@foo. com</email>
<link manager="Big.Bo ss"/>
</person>
<person id="two.worker" >
<name><family>W orker</family> <given>Two</given></name>
<email>tw*@foo. com</email>
<link manager="Big.Bo ss"/>
</person>
<person id="three.worke r">
<name><family>W orker</family> <given>Three</given></name>
<email>th***@fo o.com</email>
<link manager="Big.Bo ss"/>
</person>
<person id="four.worker ">
<name><family>W orker</family> <given>Four</given></name>
<email>fo**@foo .com</email>
<link manager="Big.Bo ss"/>
</person>
<person id="five.worker ">
<name><family>W orker</family> <given>Five</given></name>
<email>fi**@foo .com</email>
<link manager="Big.Bo ss"/>
</person>
</personnel>
<!-- XML ENDS HERE -->