Menu

Problem accesing to elements

iOne
2004-08-05
2004-08-09
  • iOne

    iOne - 2004-08-05

    First, sorry for my english. I'm spanish and i have small problems with the language.

    I have one problem with TinyXml. I have the next xml document (from the main page of the project):

    <?xml version="1.0" standalone=no>
    <!-- Our to do list data -->
    <ToDo>
         <Item priority="1"> Go to the <bold>Toy store!</bold></Item>
         <Item priority="2"> Do bills</Item>
    </ToDo>

    I want to acces to the first item, Item priority="1". I try:

    TiXmlHandle docHandle(&doc);
    TiXmlElement* child = docHandle.FirstChild("ToDo").FirstChild("Item").Element();
    if (child){
        // do something useful
    }

    Well, this is correct. But if i try to access to a no-existing member, for example, Item2:

    TiXmlElement* child = docHandle.FirstChild("ToDo").FirstChild("Item2").Element();
    if (child){
        // the program crashes
    }

    the program crashes and break. What can i do for check if an element exist? I need parse a documents with elements of which I don't know the name. If i could acces with de "docHandle", the program is very easy of programming. Any idea? Thank you.

    Sorry for my english...

     
    • Ellers

      Ellers - 2004-08-09

      Hi there,
      I don't see the problem from your code..
      Can you post a small but complete program that shows the problem? 
      Ellers

       

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.