Connecting Tech Pros Worldwide Forums | Help | Site Map

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

=?Utf-8?B?c2lwcHl1Y29ubg==?=
Guest
 
Posts: n/a
#1: Jul 11 '08

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

Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#2: Jul 11 '08

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
Closed Thread