471,356 Members | 1,676 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,356 software developers and data experts.

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
Jul 11 '08 #1
1 1282
sippyuconn <si********@newsgroup.nospamwrote:
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 - <sk***@pobox.com>
Web site: http://www.pobox.com/~skeet
Blog: http://www.msmvps.com/jon_skeet
C# in Depth: http://csharpindepth.com
Jul 11 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by psb | last post: by
1 post views Thread by mr_dom_is | last post: by
reply views Thread by mr_dom_is | last post: by
6 posts views Thread by Rob Meade | last post: by
2 posts views Thread by =?Utf-8?B?QVRU?= | last post: by
5 posts views Thread by heday60 | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.