|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
XmlReader and first charI've a string that contains a Xsl transformation : string tranform = @" <xml version=""1.0""> <xsl .....> "; Notice that the first chars are \r\n I write this string into a MemoryStream, then I create a new XmlReader like this : XmlReader reader = XmlReader.Create(myMemoryStream); This line throw an exception : the char 0x00 is not valid. If I slightly change the code : string tranform = @"<xml version=""1.0""> <xsl .....> "; (the content starts with the declaratibe tag) The code then works correctly. So my question is : why does the first \r\n make the XmlReader throw an Exception ? I thought spaces are ignored (W3C specs). Thanks in advance for any clarifications Steve When you stream, the streamreader will attempt to determine if the entire
transmission is bogus or not. A null char is a definite signal that the stream is bad or non-existent. I am not sure why the white space in the first position would be seen as a null char, but I am not overly surprised either. Remember that files, with the exception of ascii files, begin with real characters, not white space. It appears the mentality of working with binary files was extended to XML (incorrectly? perhaps). -- Show quoteGregory A. Beamer MVP; MCP: +I, SE, SD, DBA ************************************************* Think outside of the box! ************************************************* "Steve B." <steve_beauge@com.msn_swap_msn_and_com> wrote in message news:e6cg5vy1GHA.4176@TK2MSFTNGP06.phx.gbl... > Hi, > > I've a string that contains a Xsl transformation : > > string tranform = @" > <xml version=""1.0""> > <xsl .....> > "; > > Notice that the first chars are \r\n > > I write this string into a MemoryStream, then I create a new XmlReader > like this : > > XmlReader reader = XmlReader.Create(myMemoryStream); > > This line throw an exception : the char 0x00 is not valid. > If I slightly change the code : > > string tranform = @"<xml version=""1.0""> > <xsl .....> > "; > > (the content starts with the declaratibe tag) > > The code then works correctly. > > So my question is : why does the first \r\n make the XmlReader throw an > Exception ? I thought spaces are ignored (W3C specs). > > Thanks in advance for any clarifications > Steve > Cowboy (Gregory A. Beamer) <NoSpamMgbworld@comcast.netNoSpamM> wrote:
> When you stream, the streamreader will attempt to determine if the entire My guess is that the stream has been created using a UTF-16 (or > transmission is bogus or not. A null char is a definite signal that the > stream is bad or non-existent. I am not sure why the white space in the > first position would be seen as a null char, but I am not overly surprised > either. similar) encoding, giving 0 as the first byte. > Remember that files, with the exception of ascii files, begin with real On what grounds? There's not reason why a text file stored in UTF-16 shouldn't > characters, not white space. start with spaces, for instance. It wouldn't be valid XML, but it's a perfectly reaosnable text file. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too "Jon Skeet [C# MVP]" <sk***@pobox.com> wrote in message That would make sense. I will file that one away in a place where it is news:MPG.1f726a1fbddb259798d464@msnews.microsoft.com... > Cowboy (Gregory A. Beamer) <NoSpamMgbworld@comcast.netNoSpamM> wrote: >> When you stream, the streamreader will attempt to determine if the entire >> transmission is bogus or not. A null char is a definite signal that the >> stream is bad or non-existent. I am not sure why the white space in the >> first position would be seen as a null char, but I am not overly >> surprised >> either. > > My guess is that the stream has been created using a UTF-16 (or > similar) encoding, giving 0 as the first byte. accessible. :-) >> Remember that files, with the exception of ascii files, begin with real Okay, you have me on point #2. :-)>> characters, not white space. > > On what grounds? There's not reason why a text file stored in UTF-16 > shouldn't > start with spaces, for instance. It wouldn't be valid XML, but it's a > perfectly reaosnable text file. I got a bit too focused on XML. -- Gregory A. Beamer MVP; MCP: +I, SE, SD, DBA ************************************************* Think outside of the box! ************************************************* Steve B. <steve_beauge@com.msn_swap_msn_and_com> wrote:
<snip> > So my question is : why does the first \r\n make the XmlReader throw an Spaces are ignored (to some extent) in most of XML, but looking at the > Exception ? I thought spaces are ignored (W3C specs). specs I can't see anything in the definition of the prolog part of the XML which allows whitespace before the XMLDecl part. -- Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet Blog: http://www.msmvps.com/jon.skeet If replying to the group, please do not mail me too |
|||||||||||||||||||||||