Menu

Leading and trailing whitespace in Element

2005-10-13
2013-05-20
  • karam_chand

    karam_chand - 2005-10-13

    Hello,

    I have been using TiXML without any problem for couple of my projects now but I just came upon an issue.

    I have data like:

    <a>    data</a>

    But:

    TiXmlText* text->Value()

    always seems to return:

    data (the leading and trailing white spaces are removed.

    It happens the same with IE too so I think its a behavior of XML itself.

    I have even set SetCondenseWhiteSpace (...) to false but of no avail. It always returns data with leading and trailing white space removed.

    Anyway, I can keep the space intact? Its kinda important in what I am doing.

    Karam

     
    • Ellers

      Ellers - 2005-10-13

      There is no such thing as "behaviour of XML itself". XML is just bytes, in a file, over a stream, etc. If the byte array contains spaces (or other whitespace chars) then there are spaces/whitespace in the byte array. End of story.

      However - its up to the parser how it interprets those bytes, and some choose the HTML approach - condense the whitespace.

      Personally, I find any manipulation of my data inappropriate.  In TinyXml try turning it off with SetCondenseWhiteSpace(false).

      HTH
      Ellers

       
    • Lee Thomason

      Lee Thomason - 2005-10-13

      I believe - I haven't looked at that part of the code in a while - that white space condensing only applies to the interior space, not the space before or after the element text. There was quite a bit of debate about this a couple of years ago and that was settled on as the least offensive solution.

      The current XML spec:
      http://www.w3.org/TR/2004/REC-xml-20040204/#sec-white-space

      is not clear on the topic. Apparently putting examples or clarifying points in specs is considered by W3C to be pandering to the technologically unworthy.

      In any case, this is an area of future improvement for TinyXML.

      lee

       

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.