473,581 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(sX ML.Length);
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er
binaryFormatter = new
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er();
binaryFormatter .Serialize(stre am, sXML);
stream.Position = 0;

xs.ReadXml(stre am);

//This works just fine
System.Xml.XmlR eader rdr = System.Xml.XmlR eader.Create(ne w
System.IO.Strin gReader(sXML));

xs.ReadXml(rdr) ;

curious what is different???

Thanks
Jul 11 '08 #1
1 1357
sippyuconn <si********@new sgroup.nospamwr ote:
sXML - has XML string
//This dies on ReadXML - something about invalid character
MemoryStream stream = new MemoryStream(sX ML.Length);
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er
binaryFormatter = new
System.Runtime. Serialization.F ormatters.Binar y.BinaryFormatt er();
binaryFormatter .Serialize(stre am, sXML);
stream.Position = 0;

xs.ReadXml(stre am);
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.G etBytes(sXML) (or whatever encoding the
XML is in) then it should be okay.

--
Jon Skeet - <sk***@pobox.co m>
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
1074
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. I don't want to do that long term... too much fileIO. I guess I am asking, how do I convert a string to Xml.XmlReader, IO.Stream, or...
1
5812
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
5677
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 I convert data type of one of the column to integer and then I use the Dataset.ReadXml function and pass the same file to it. This works on my...
0
1469
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
2628
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, reader2, after creating new XmlReaderSettings and a new XmlParserContext. // customContext and customSettings may or may not make use reader1's...
6
2398
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. Having checked the info for XML file reading it suggests that with .net 2.0 you should use the XMLReader class...
1
3621
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 xsd:restriction conditions are ingested without a murmur. Is this a bug or a feature? Very frustrating. Evidence: 1) XML data <?xml...
2
1465
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 ones (the last few hundreds). Unfortunately, the readxml loads the whole 10 000s of them. Is there a way to specify the loading of the last few...
5
3176
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 dir.GetFiles("*.xml")) { try { ParseXML(file.FullName); }
2
5571
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 bytes into utf-8. MemoryStream ms = new MemoryStream(); XmlTextWriter xmlWriter = new XmlTextWriter(ms, new UTF8Encoding(false)); ...
0
7857
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7788
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
8137
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
7890
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
8163
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
1
5667
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5355
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3813
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1127
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.