Connecting Tech Pros Worldwide Help | Site Map

Use ReadXML of XSD works with XMLReader but not with Stream-any id

 
LinkBack Thread Tools Search this Thread
  #1  
Old July 11th, 2008, 01:45 AM
=?Utf-8?B?c2lwcHl1Y29ubg==?=
Guest
 
Posts: n/a
Default Use ReadXML of XSD works with XMLReader but not with Stream-any id


sXML - has XML string


//This dies on ReadXML - something about invalid character
MemoryStream stream = new MemoryStream(sXML.Length);
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter
binaryFormatter = new
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();
binaryFormatter.Serialize(stream, sXML);
stream.Position = 0;

xs.ReadXml(stream);

//This works just fine
System.Xml.XmlReader rdr = System.Xml.XmlReader.Create(new
System.IO.StringReader(sXML));

xs.ReadXml(rdr);

curious what is different???

Thanks

  #2  
Old July 11th, 2008, 05:25 AM
Jon Skeet [C# MVP]
Guest
 
Posts: n/a
Default Re: Use ReadXML of XSD works with XMLReader but not with Stream-any id

sippyuconn <sippyuconn@newsgroup.nospamwrote:
Quote:
sXML - has XML string
>
>
//This dies on ReadXML - something about invalid character
MemoryStream stream = new MemoryStream(sXML.Length);
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter
binaryFormatter = new
System.Runtime.Serialization.Formatters.Binary.Bin aryFormatter();
binaryFormatter.Serialize(stream, sXML);
stream.Position = 0;
>
xs.ReadXml(stream);
You're uing a binary formatter on the string, which is likely to add
extra stuff to indicate that it *is* a string.

If you just use Encoding.UTF8.GetBytes(sXML) (or whatever encoding the
XML is in) then it should be okay.

--
Jon Skeet - <skeet@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 220,840 network members.