Search code examples
xmlw3c

How whitespace (in data) is treated by XML Parser?


If this is a sample XML::

<root>
  <tag1>data
    data
     data</tag1>
  <tag2>
  </tag2>
  <tag3> </tag3>
</root>

This file is viewed differently in different browsers and XML viewer/editors,

some viewers display 1st <tag/> element as <tag>data data data</tag> some display as is,
Some viewers, treat new line as nbsp(space) and some treat space and new line as null,

What is the standard approach for this white-space issue?


Solution

  • Conclusion
    I validated the same XML against XSD which had defined <tag1/> <tag2/> ... with enumeration values, (copied same value of the tags) when I altered the contents of <tag> by adding/removing whitespace. The schema acknowledged mismatch which concludes that .. in general XML parser won't ingore the whitespace :) But the transformation ignores whitespace, thats why the browsers ignore it too where as notepad is honest to display as is. ;)

    Source/courtesy :: Nic Gibson's comment on jambox's answer