Menu

crash: reading empty nodes

2005-02-15
2013-05-20
  • Dr. Bernhard Friedrichs

    I have a problem reading code like

            <output_file>
              <line_num></line_num>
              <site_num></site_num>
              <run_num></run_num>
                ........
    or
    <coordinates_external>
        <Latitude />
        <Longitude />
        <Elevation />
        <Ellipsoid>WGS84</Ellipsoid>
        <UTM_Northing />
           .............

    with my simple function

        while (node->NextSibling() ) {                                              // keep the level            
          node = node->NextSibling();
          if (node->FirstChildElement() ) {                                         // this is a node - we have to step down later
            cerr << endl << tabs(had_a_node) << "<" << node->Value() <<">";
            had_a_node++;
            xnode = node;
            break;
          }
          tnode = node->FirstChild();
          cerr << endl << tabs(had_a_node) <<  "<" << node->Value() << "> " << tnode->Value();
        }

    and so on;
    However: if the nodes are filled - no problem; getting empty nodes as above, the code crashes; so testing with while (node->NextSibling() ) does not work.
    What can I do??

    Ps: reading something like this is ok:
            <output_file>
              <line_num>x</line_num>
              <site_num>x</site_num>
              <run_num>x</run_num>

     
    • diilbert

      diilbert - 2005-02-15

      I have the same problem.  If any of the tags have empty values the program will crash.  Is there anyway to handle this?  Since it is possible they will be empty at some point.

       
    • Lee Thomason

      Lee Thomason - 2005-02-16

      The XML, as stated, seems fine. I ran it through the test bed.

      It's hard to tell for sure what is happening from your code. If 'node' refers to output_file (the root) then it doesn't have a sibling, and the program will crash when you dereference it.

      If node refers to line_num, then the next will work. But it has no child element, so, once again, dereferencing it will crash your code.

      lee

       

Log in to post a comment.