Re: [xml] Traversing a XML Document
- From: "William M. Brack" <wbrack mmm com hk>
- To: "Dinesh Ahuja" <mdlinux7 yahoo co in>
- Cc: xml gnome org
- Subject: Re: [xml] Traversing a XML Document
- Date: Wed, 14 Jul 2004 19:34:33 +0800 (HKT)
Dinesh Ahuja said:
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
Let me answer your question with a question: have you looked at the
FAQ that accompanies the library? Or from the net, try
http://xmlsoft.org/FAQ.html#Developer and look at Paragraph 3?
Bill
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]