TinyXML-2

2012-03-01
2013-05-20
  • Lee Thomason
    Lee Thomason
    2012-03-01

    TinyXML-1 has been a wildly successful project, and continues to be available here and widely used. My many thanks.

    I've re-written the parser of TinyXML to use much less memory, perform better, use a little more modern C++, but use a very similar API. After years of talking about writing it, I'm pleased to announce that TinyXML-2 is available on github:

    https://github.com/leethomason/tinyxml2

     
  • Franziska
    Franziska
    2012-06-05

    Hi there,

    I want to read the data from a wxGrid and write it into a XML File.

    The wxGrid is like:

    > Jahr Monat
    2012 03
    2009 08

    What I want to have:
    <SQL>
        <Datensatz>
            <Jahr>2012</Jahr>
            <Monat>03</Monat>
        </Datensatz>
        <Datensatz>
            <Jahr>2009</Jahr>
            <Monat>08</Monat>
        </Datensatz>
    </SQL>

    What I got:
    <SQL>
        <Datensatz>
            <Jahr>20122009</Jahr>
            <Monat>0308</Monat>
        </Datensatz>
        <Datensatz>
            <Jahr>20122009</Jahr>
            <Monat>0308</Monat>
        </Datensatz>
    </SQL>

    My Code:

        XMLDocument doc;
        XMLElement* xesql = doc.NewElement("SQL");
        XMLNode * xnsql = doc.InsertFirstChild(xesql);
        XMLElement* xejahr = doc.NewElement("Jahr");
        XMLElement* xemonat = doc.NewElement("Monat");
        XMLText* datensatzJahr = doc.NewText("");
        XMLText* datensatzMonat = doc.NewText("");
        for(int i=0; i<=1; i++)
        {
            XMLElement* xedatensatz = doc.NewElement("Datensatz");
            datensatzJahr = doc.NewText(m_gd_data->GetCellValue(i,0));
            datensatzMonat = doc.NewText(m_gd_data->GetCellValue(i,1));
            xejahr->InsertEndChild(datensatzJahr);
            xemonat->InsertEndChild(datensatzMonat);
            xedatensatz->InsertEndChild(xejahr);
            xedatensatz->InsertEndChild(xemonat);
            xesql->InsertEndChild(xedatensatz);
        }
        doc.SaveFile(path);
    

    I really don't know where's the problem. Can anyone help?

     
  • Franziska
    Franziska
    2012-06-05

    Problem solved - for others with same problem:

    for(int i=0; i<=1; i++)
        {
            XMLElement* xedatensatz = doc.NewElement("Datensatz");
            XMLElement* xejahr = doc.NewElement("Jahr");
            XMLElement* xemonat = doc.NewElement("Monat");
            datensatzJahr = doc.NewText(m_gd_data->GetCellValue(i,0));
            datensatzMonat = doc.NewText(m_gd_data->GetCellValue(i,1));
            xejahr->InsertEndChild(datensatzJahr);
            xemonat->InsertEndChild(datensatzMonat);
            xedatensatz->InsertEndChild(xejahr);
            xedatensatz->InsertEndChild(xemonat);
            xesql->InsertEndChild(xedatensatz);
     }