473,387 Members | 1,844 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 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 1346
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: psb | last post by:
Hello, this might be a newbie xml question... I am trying to use the DataSet.ReadXml() method with a string of xml. Right now, I save it to a file and then supply the method with the file name....
1
by: mr_dom_is | last post by:
Hi I have a little bit of trouble, probably missing the point now sure but: I have a dataset dim ds as new dataset("User") Which is populated with data from a database. When I use
8
by: Nikhilesh Mehendale | last post by:
I have written a web service in C#, .NET 1.1 which reads a XML file into a dataset. This is just a plain XML file. First I use the Dataset.ReadXmlScheme function and pass the XML file to it. Then...
0
by: mr_dom_is | last post by:
Hi I have a little bit of trouble, probably missing the point not sure but: I have a dataset dim ds as new dataset("User") Which is populated with data from a database. When I use
0
by: Jen | last post by:
My main question: "How can I get a TextReader or Stream object from an existing XmlReader?". Read on for more: I have an existing XmlReader. Let's call it reader1. I'm creating another reader,...
6
by: Rob Meade | last post by:
Hi all, I'm having a few difficulties with the above, ie I cant find any good examples anywhere of how to do what I want to do! I have an xml file on my desktop which I want to read in. ...
1
by: Mac | last post by:
I'm trying to validate input from an xml source to a dataset in dotnet2.0. As far as I can see, type errors correctly cause an exception, but values that are the correct type but do not satisify...
2
by: =?Utf-8?B?QVRU?= | last post by:
Hi, I have an xml file that can contain a lot of records and I am using dataset.readxml to read in the file. When looking on what I do with those records, I am interested only the most recent...
5
by: heday60 | last post by:
I've got this application that watches a directory for XML's and then parses them into a DB. It then moves them based on if the XML was succesful or a bad XML... foreach(FileInfo file in...
2
by: SammyBar | last post by:
Hi all, I'm trying to convert the xml obtained from a XmlReader object into a UTF-8 array. My general idea is to read the XmlReader and write into a MemoryStream. Then convert the MemoryStream...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.