Menu

Parse bug?

Instructor
2005-09-27
2013-05-20
  • Instructor

    Instructor - 2005-09-27

    XML file looks like:

    <?xml version="1.0" standalone="no" ?>
    <ToDo>
        <!-- Do I need a secure PDA? -->
    </ToDo>

    But after:

    void main()
    {
        TiXmlDocument doc;
        TiXmlDocument doc2;
        TiXmlNode *root=0;
        TiXmlNode *node=&doc2;

        doc.LoadFile("demotest.xml", TIXML_DEFAULT_ENCODING);

        root=doc.RootElement();
        node->Parse("<a>b</a>", 0, TIXML_DEFAULT_ENCODING);
        root->InsertEndChild(*node);

        doc.SaveFile();
    }

    It looks like:

    <?xml version="1.0" standalone="no" ?>
    <ToDo>
        <!-- Do I need a secure PDA? -->
        <a>b</a>

    </ToDo>

    unnecessary \r\n appeared

     
    • Lee Thomason

      Lee Thomason - 2005-09-28

      Interesting. Could you file this as a bug and include a zip of your code snippet / xml?

      thanks very much,
      lee

       
    • Instructor

      Instructor - 2005-09-28
       
    • Instructor

      Instructor - 2005-10-16

      Unfortunately v2.4.0 don't fix this bug :(

       
    • Lee Thomason

      Lee Thomason - 2005-10-18

      We'll pick it up in the next one.
      lee

       
    • Ellers

      Ellers - 2005-10-22
       
    • Instructor

      Instructor - 2005-10-22

      Cool, thanks!

       
    • Instructor

      Instructor - 2005-10-22

      I found something strange:
      "TextNode->InsertEndChild(&SomeNode)" should be NULL, but...

      Example (demotest.xml):
      <?xml version="1.0" standalone="no" ?>
      <ToDo>
          <b>city</b>
      </ToDo>

      Example (test.cpp):
      #include "tinyxml.h"
      #include <stdio.h>

      void main()
      {
          TiXmlDocument doc;
          TiXmlElement element("");
          TiXmlNode *node;

          doc.LoadFile("demotest.xml", TIXML_DEFAULT_ENCODING);

          element.Parse("<ElName>My Text</ElName>", 0, TIXML_DEFAULT_ENCODING);
          node=doc.RootElement()->FirstChildElement()->FirstChild();

          if (node=node->InsertEndChild(element))
              printf("This message should not be shown:\n%s\n%s\n", node->Value(), node->Parent()->Value());

          doc.SaveFile("demotest_2.xml");
      }

       
    • Instructor

      Instructor - 2005-10-23

      I found the solution:

      if (TextNode->ToElement())
        TextNode->InsertEndChild(&SomeNode);

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.