Menu

Probably a Dumb Question

diilbert
2005-02-09
2013-05-20
  • diilbert

    diilbert - 2005-02-09

    I really like your parser and I want to use it in a project I am working on, but I am still cannot figure out how to get the text between two tags.

    Here is the xml I am using...

    <test>
      <item>TEST</item>
    </test>

    Here my code (very simple)

    TiXmlDocument doc;

    Load file to doc;
    Check for errors ;

    TiXmlNode* node = 0;
    TiXmlElement* itemElement = 0;
        
    node = doc.RootElement();

    node = node->FirstChild();
    itemElement = node->ToElement();
       
    assert(itemElement);
       
    printf("Type: %i\r\n",itemElement->Type());
    printf("Item Element: %s\r\n",itemElement->Value());

    This one of the several ways I have tried it but it keeps giving me the "item" tag name in that last printf. (I have tried these methods according to the xmltest.cpp file)

    Thanks in advance :)
    Diilbert

     
    • Andrew Ziem

      Andrew Ziem - 2005-02-09

      I think it was the same problem I had and posted about this week.  It turns out that you need to go down one more using FirstChild(). 

      See <https://sourceforge.net/forum/forum.php?thread_id=1225127&forum_id=42748>.

       
      • Ellers

        Ellers - 2005-02-09

        There's part of me that thinks "yes, obviously a text node is contained in the element node".

        But the other part of me (the, er, nicer part ;) can remember when all of this stuff was unclear and confusing.

        The good news is that this approach is common in the general DOM approach to XML processing, so if/when you work with other toolkits, you won't be as surprised :)

        Perhaps if multiple people are having these sorts of problems the intro TinyXml doc could start off with some simple examples?

         
        • B Sizer

          B Sizer - 2005-02-09

          There is an example on the main page of the docs, which shows how a sample XML file breaks down into nodes, including several TiXmlText elements. I know it's perhaps not very intuitive but it is definitely documented.

           
          • Ellers

            Ellers - 2005-02-09

            True. And its all there in the sample/test program too, although it takes a bit of reading to get to. Just sometimes for beginners it might be good to hand-hold through some basic steps up front and early in the docs :)

             
    • diilbert

      diilbert - 2005-02-09

      Andrew:  Thanks...

      According to what I read on the main doc page of the web page my code should have worked.....

      Oh well... thanks anyway :p

      By the way thanks for the awesome class :)

       

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.