Dom Traversal Help Needed (Xerces / C++)

X

Xamalaek

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/[email protected]&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->setValidationScheme(gValScheme);
parser->setDoNamespaces(gDoNamespaces);
parser->setDoSchema(gDoSchema);
parser->setValidationSchemaFullChecking(gSchemaFullChecking);
parser->setCreateEntityReferenceNodes(gDoCreate);

DOMTreeErrorReporter *errReporter = new DOMTreeErrorReporter();
parser->setErrorHandler(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->getDocumentElement();
DOMTreeWalker *walker =
sensorml_doc->createTreeWalker(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::transcode(current_node->getNodeName());
std::cout << "NodeValue: " << strValue << std::endl;
XMLString::release(&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.dtd">
<personnel>
<person id="Big.Boss" >
<name><family>Boss</family> <given>Big</given></name>
<email>[email protected]</email>
<link subordinates="one.worker two.worker three.worker four.worker
five.worker"/>
</person>
<person id="one.worker">
<name><family>Worker</family> <given>One</given></name>
<email>[email protected]</email>
<link manager="Big.Boss"/>
</person>
<person id="two.worker">
<name><family>Worker</family> <given>Two</given></name>
<email>[email protected]</email>
<link manager="Big.Boss"/>
</person>
<person id="three.worker">
<name><family>Worker</family> <given>Three</given></name>
<email>[email protected]</email>
<link manager="Big.Boss"/>
</person>
<person id="four.worker">
<name><family>Worker</family> <given>Four</given></name>
<email>[email protected]</email>
<link manager="Big.Boss"/>
</person>
<person id="five.worker">
<name><family>Worker</family> <given>Five</given></name>
<email>[email protected]</email>
<link manager="Big.Boss"/>
</person>
</personnel>


<!-- XML ENDS HERE -->
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,051
Latest member
CarleyMcCr

Latest Threads

Top