[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"?>
<story>
</story>

My traversing function is as follows :

void myTraverseDocument(xmlNodePtr pNodePtr) {

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

while (pTempPtr != NULL) {

printf("Element Name is : %s
\n",(char*)pTempPtr->name); 
pTempPtr = pTempPtr->next;
if (pTempPtr != NULL) {
if (pTempPtr->xmlChildrenNode != NULL) {
        myTraverseDocument(pTempPtr);
}
}               
}
}

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
\n",(char*)pTempPtr->name);
}

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
Dinesh-Ahuja



________________________________________________________________________
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]