Menu

TinyXML seems not fully conform to XML spec

2005-10-30
2013-05-20
  • flamingheart

    flamingheart - 2005-10-30

    the spec prescribes that every XML file must have and only have one root element. but the XML file below is also OK in TinyXML which dose not conform to XML spec

    <?xml version="1.0" standalone="no" ?>
    <passages count="006" >
        <psg context='Line 5' />
    </passages>
    <error>
        something
    </error>

     
    • Ellers

      Ellers - 2005-10-30

      Its true that TinyXML will load a document with more than one root node. I recently posted a response to another poster who was loading something like:

      <?xml ...?>
      <!-- a comment -->
      <root>
      Stuff
      </root>

      This is also not "valid XML", but TinyXML will load it.

      I think the moral of the story here is that TinyXML is doing *more* than the spec, which although it has issues, is not necessarily a bad thing.

       
      • Yves Berquin

        Yves Berquin - 2005-11-05

        Ellers,

        It would be easy to add a check function in a TinyXML document to see if it has only one root element, that is, if it's root element has no sibling.
        The one XML you posted here seem valid to me. What's wrong with it ?

        Yves

         
        • Ellers

          Ellers - 2005-11-06

          Hey Yves,
          True. I think the OP has a good point that TinyXml should conform to the spec. It might break some existing code butt arguably its better to do that.

          The XML I posted before (and below) is broken because the comment is a node in the DOM at the root level. Technically this XML therefore has > 1 root node, which breaks the spec.

          // broken XML (2 root nodes)
          <?xml verson="1.0" ?>
          <!-- a comment -->
          <root>
          Stuff
          </root>

          // valid XML (1 root node)
          <?xml verson="1.0" ?>
          <root>
          <!-- a comment -->
          Stuff
          </root>

          // clearly broken - 2 root nodes
          <?xml verson="1.0" ?>
          <one/>
          <two/>

          Having said all that, I'm not sure how many parsers would consider the comment-at-root-level an error or not.

           
          • Yves Berquin

            Yves Berquin - 2005-11-15

            I'm not sure I agree with the fact that a comment at root level break the specs.

            Here are some rules from the xml 1.0 specs (http://www.w3.org/TR/2004/REC-xml-20040204/) :

            [1] document       ::=       prolog element Misc*
            [22]       prolog       ::=       XMLDecl? Misc* (doctypedecl Misc*)?
            [27]       Misc       ::=       Comment | PI | S

            From this, any number of comments can be found in the prolog, that is, before the root-and-only element

            Yves

             
    • Lee Thomason

      Lee Thomason - 2005-11-13

      I submitted a bug - I think this one is worth cleaning up.

      lee

       

Log in to post a comment.