[xml] traverse a tree

Hi list,
I want to parse a tree and read out the attribues and values. I wrote two functions to do so:

void CXMLTreeWalk::getPropsFromChildren(xmlDocPtr doc, xmlNodePtr cur){

xmlChar* szText;

static int iYPos;

int iXPos, iLength;

cur = cur->xmlChildrenNode;

while (cur != NULL) {

if ((!xmlStrcmp(cur->name, (const xmlChar *) RECORDNODE))) {

iYPos = getIntProp(cur,"YPos");

printf("YPOS %d\n", iYPos);


if ((!xmlStrcmp(cur->name, (const xmlChar *) TEXTNODE))) {

iXPos = getIntProp(cur,"XPos");

printf(" XPOS %d\n", iXPos);

iLength = getIntProp(cur,"Length");

szText = xmlNodeListGetString(doc,cur->xmlChildrenNode, 1);




cur = cur->next;




void CXMLTreeWalk::traverseTree()


while(m_cur != NULL) {

if((!xmlStrcmp(m_cur->name, (const xmlChar *) ROOTNODE)))


getPropsFromChildren(m_doc, m_cur);





It seems to work, but I don't know if there is a more efficient or/and a simpler way in achieving this. Can somebody tell me if there are mistakes I made?


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