Re: [xml] general help with using XPath with libxml2 (fwd)



Hi

Check if this attachment helps you

Regards
Sri 

 

-----Original Message-----
From: Peter Wilkes [mailto:pwilkes cowpie acm vt edu] 
Sent: Tuesday, November 14, 2006 2:20 AM
To: xml gnome org
Subject: [xml] general help with using XPath with libxml2 (fwd)

hello,

        i've been asked to convert some XML parsing code that relys on
XPath from the Microsoft XML objects to another platform independent
toolkit.  libxml seems very light weight (which is good for us) and easy
to use.  i have some questions though as i am a newbie to XML/XPath and
libxml2.

1. i have an xmlXPathObjectPtr which points to an array of objects each
containing data X, Y, and Z. i would like to look up the field by name.
ex. Lookup(MyxmlXPathObjectPtr, "field1"); currently i have this solved
by doing a short while loop.

xmlNodePtr nodePtr = nodeSet->nodeTab[pos]; if(nodePtr == NULL) {
        return false;
}

bool found = false;
xmlNodePtr runner = nodePtr->children;
while( (runner != NULL) && (!found) )
{
        if(strcmp(element, (char *)runner->name) == 0)
        {
                strncpy(val, (char *)runner->children->content, valLen);
                found = true;
        }
        runner = runner->next;
}

frankly i figured that this was the wrong way of doing this. and i'm
looking for a better way to accomplish the same goal.  i cant seem to
find the correct function inside libxml2 or dont fully understand the
naming conventions. (again i am a noob)  any help anyone can give me is
greatly appreciated.

2. i have a xmlXPathObjectPtr which points to an array of objects.  one
of those object being a array itself.  (array contained inside an array)
and i cant seem to figure out how to get the subarray from my array. an
example would be like

<data>
        <array1>
                <array2>
                        <MyStruct>
                                <data1>data1</data1>
                                <data2>data2</data2>
                        </MyStruct>
                        <MyStruct>
                                <data1>data11</data1>
                                <data2>data22</data2>
                        </MyStruct>
                </array2>
                <array2>
                        <MyStruct>
                                <data1>data111</data1>
                                <data2>data222</data2>
                        </MyStruct>
                        <MyStruct>
                                <data1>data1111</data1>
                                <data2>data2222</data2>
                        </MyStruct>
                </array2>
        </array1>
</data>

again if anyone could provide me with any hints i would be very
appreciated.


thanks

Pete
_______________________________________________
xml mailing list, project page  http://xmlsoft.org/ xml gnome org
http://mail.gnome.org/mailman/listinfo/xml

Attachment: parse_function.txt
Description: parse_function.txt



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