need to get the child nodes in same order

96 Views Asked by At

I have an xml file as below:

<bookstore>
    <book category="xyz">
        <title lang="en">some</title>
        <author>abc</author>
        <year>2005</year>
        <price>30.00</price>
    </book>
    <book category="children">
        <title lang="en">Harry Potter </title>
        <author>Rowling</author>
        <year>2005</year>
        <price>29.99</price>
    </book>
</bookstore>

I need the child nodes of book to be in same order as book(no parent child nodes). The resulting xml should look like below:

<bookstore>
    <book category="xyz">
    <title lang="en">some</title>
    <author>abc</author>
    <year>2005</year>
    <price>30.00</price>
    </book>
    <book category="children">
    <title lang="en">Harry Potter </title>
    <author>Rowling</author>
    <year>2005</year>
    <price>29.99</price>
    </book>
</bookstore>

The code snippet for the same is as below::

pXMLEventList = pXMLDoc->getElementsByTagName("book");
int numEvent = pXMLEventList->Getlength();
for(int evntCount = 0; evntCount < numEvent; evntCount++)
{   

    /*Read the xml file in a away wherein all the childnodes   
    at same level as of root node */
    pXMLEventDoc = pXMLEventList->item[evntCount];
    pXMLNodeList = pXMLEventDoc->getElementsByTagName("*");
    int count = pXMLNodeList->Getlength();
}   

But pXMLEventDoc is always NULL. Can someone please help me in this.

Thanks

0

There are 0 best solutions below