TinyXML code works. But not for comlete File

daniel_b
2009-06-28
2013-05-20
  • daniel_b
    daniel_b
    2009-06-28

    Hi,
    I have some problem with my tinyXML programm.
    I have a XML Strink like this:

    -------------------------------------------------------------------------------
    <?xml version=\&quot;1.0\&quot; ?>
    <Packet>
        <ParsedDataElement>
            <Name>name1</Name>
            <RawValue>1</RawValue>
        </ParsedDataElement>
        <ParsedDataElement>
            <Name>name2</Name>
            <RawValue>2<RawValue>
        </ParsedDataElement>
        <ParsedDataElement>
            <Name>name3</Name>
            <RawValue>3</RawValue>
        </ParsedDataElement>
        <ParsedDataElement>
            <Name>name4<Name>
            <RawValue>4</RawValue>
        </ParsedDataElement>
        <ParsedDataElement>
            <Name>name5</Name>
            <RawValue>5</RawValue>
        <ParsedDataElement>
    </Packet>
    -------------------------------------------------------------------------------

    For parsing this this XML string I wrote this source-code:
        TiXmlDocument doc;
        doc.Parse(xmlStr); //this string is the xml string (see above)
        TiXmlHandle hDoc(&doc);

        //TiXmlHandle* motePacket; //first Node
        TiXmlElement* pElem;
        TiXmlElement* pElemLev2;
        TiXmlHandle hRoot(0), nextRoot(0);

        pElem=hDoc.FirstChildElement().FirstChildElement().Element(); //parsedData
            while(pElem){
                pElemLev2=(TiXmlHandle(pElem)).FirstChildElement().Element();
                nextRoot=TiXmlHandle(pElem);
                if(pElemLev2){
                    cout<<pElemLev2->GetText();
                    pElemLev2=pElemLev2->NextSiblingElement();
                    cout<<": "<<pElemLev2->GetText()<<endl;
                }
                pElem=pElem->NextSiblingElement();
            }

    But I get only the first two components:
    name1: 1
    name2: 2

    What is the mistake at my source code? Or how can I write it to realizes this szenario.
    Thanks for your help