EDN Admin
Well-known member
Hello,
I have an application that uses an XmlTextReader to iterate and parse the nodes in an XML document. The function Read() is used as a loop invariant, of course with a return value of false indicating (per the docs) that there are no more nodes to read.
The issue Im encountering is that if the file contains white space after the closing tag of the root element, then an exception with a message "<span style="white-spacere-wrap hexadecimal value 0x00, is an invalid character. " is thrown.
This happens immediately upon calling Read() after the last closing tag node has been read. For example:
<pre><?xml version="1.0"?>
<foo>
<bar>1</bar>
</foo>***CR/LF here causes error***[/code]
<span style="white-spacere-wrap The presence of white space anyplace else in the document, interleaved between the markup, has no ill affect. If I insert white space, either spaces or line break or anything else, after the last closing tag in the document
just before EOF, the error occurs.
<span style="white-spacere-wrap Firstly, is this any kind of rule that is apart of the W3C XML spec? I have read over the spec, and I see no place where white space is prohibited, except at the very start of the document before the XML declaration. If
this is a rule Ive missed, please be so gracious as to link to the place in the spec where this is explained.
<span style="white-spacere-wrap Second, if this is not covered in the spec, then why is this happening? Is this a peculiarity of the XmlTextReader and how it parses? Is there a setting in the XmlReaderSettings or something I can use to influence this
behavior? The IgnoreWhitespace setting seems to only control whether white space in the document is mapped to WhiteSpace node types and returned by Read(), or if it is simply skipped. This is different behavior, the parser is actually dying on white space
at a specific place (i.e. the end of the document).
<span style="white-spacere-wrap Appreciate any light that can be shed on this behavior and why it happens.
<span style="white-spacere-wrap Thanks,
<span style="white-spacere-wrap Mike
<br/>
View the full article
I have an application that uses an XmlTextReader to iterate and parse the nodes in an XML document. The function Read() is used as a loop invariant, of course with a return value of false indicating (per the docs) that there are no more nodes to read.
The issue Im encountering is that if the file contains white space after the closing tag of the root element, then an exception with a message "<span style="white-spacere-wrap hexadecimal value 0x00, is an invalid character. " is thrown.
This happens immediately upon calling Read() after the last closing tag node has been read. For example:
<pre><?xml version="1.0"?>
<foo>
<bar>1</bar>
</foo>***CR/LF here causes error***[/code]
<span style="white-spacere-wrap The presence of white space anyplace else in the document, interleaved between the markup, has no ill affect. If I insert white space, either spaces or line break or anything else, after the last closing tag in the document
just before EOF, the error occurs.
<span style="white-spacere-wrap Firstly, is this any kind of rule that is apart of the W3C XML spec? I have read over the spec, and I see no place where white space is prohibited, except at the very start of the document before the XML declaration. If
this is a rule Ive missed, please be so gracious as to link to the place in the spec where this is explained.
<span style="white-spacere-wrap Second, if this is not covered in the spec, then why is this happening? Is this a peculiarity of the XmlTextReader and how it parses? Is there a setting in the XmlReaderSettings or something I can use to influence this
behavior? The IgnoreWhitespace setting seems to only control whether white space in the document is mapped to WhiteSpace node types and returned by Read(), or if it is simply skipped. This is different behavior, the parser is actually dying on white space
at a specific place (i.e. the end of the document).
<span style="white-spacere-wrap Appreciate any light that can be shed on this behavior and why it happens.
<span style="white-spacere-wrap Thanks,
<span style="white-spacere-wrap Mike
<br/>
View the full article