[xml] Traversing a XML Document

I have written a function which traverse a XML
document and prints the name of the each node.

Suppose I am traversing XML document which is as below
<?xml version="1.0"?>

My traversing function is as follows :

void myTraverseDocument(xmlNodePtr pNodePtr) {

xmlNodePtr pTempPtr = NULL;
pTempPtr = pNodePtr->xmlChildrenNode;

while (pTempPtr != NULL) {

printf("Element Name is : %s
pTempPtr = pTempPtr->next;
if (pTempPtr != NULL) {
if (pTempPtr->xmlChildrenNode != NULL) {

The output of this function come as :
Root Node Name is : story
Element Name is : text

Can anyone explain me why this text is coming and from
where this node with a name text has come ?

I made a change in the above function by introducing
the check on the node type and the output came as per
my expectations. 
if (pTempPtr->type != XML_TEXT_NODE ) {
printf("Element Name is : %s

The output of the modified function is as follows:
Root Node Name is : story

Please let me know whether I am right in making the
changes in above function.

Thanks & Regards

Yahoo! India Careers: Over 50,000 jobs online
Go to: http://yahoo.naukri.com/

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]