Click here to Skip to main content
15,851,514 members
Please Sign up or sign in to vote.
3.50/5 (3 votes)
See more:
Hi All,

I have a simple xml in database as below.

<test><br />
<testcode>1</testcode><br />
<testdesc>test1</testdesc><br />

Whenever i save this as a file on my desktop and then load into a dataset, i get the datatable created automatically.

But if i load it into a string and pass it to read, i get an error message saying "Illegal Characters in Path"

Code that I use is

Dim Doc As XDocument = XDocument.Parse(RawXMLStr)

Sbill is my dataset
Rawxmlstr is my string

Any Idea as of how to eliminate this error would be greatly appreciated.
Updated 5-Nov-12 11:44am
CPallini 5-Nov-12 16:42pm    
Your simple XML doesn't look correct: last node should be </test>.
Vamshi Krishna Naidu 5-Nov-12 16:45pm    
It was a Copy error. I have to put everything in code, so i manually typed it again and I missed the "/". But I still have the same problem.
Sergey Alexandrovich Kryukov 5-Nov-12 16:59pm    
Try again -- now it's valid. (XML prolog is missing, but I don't think this is the problem.)

1 solution

The XML in your question is valid.

The problem you are experiencing is because the XMLDoc code you tried expects a file path containing xml whereas you passed in xml string content itself.

As for the solution, please see my sample below which works:

String xmlString = "<test><testcode>1</testcode><testdesc>test1</testdesc></test>";

System.Xml.XmlTextReader reader = new System.Xml.XmlTextReader(new System.IO.StringReader(xmlString));

System.Data.DataSet ds = new System.Data.DataSet();
ds.ReadXml(reader, System.Data.XmlReadMode.Auto);

UPDATE: sorry I realised afterwards your question is VB:
Dim xmlString As String = "<test><testcode>1</testcode><testdesc>test1</testdesc></test>"
Dim reader As System.Xml.XmlTextReader = New System.Xml.XmlTextReader(New System.IO.StringReader(xmlString))
Dim ds As System.Data.DataSet = New DataSet
        ds.ReadXml(reader, System.Data.XmlReadMode.Auto)
Share this answer
RaisKazi 5-Nov-12 17:15pm    
My 5.
njammy 5-Nov-12 17:34pm    
Vamshi Krishna Naidu 5-Nov-12 18:48pm    
Excellent. I tried this before but only missed XMLReadMode. Now the functionality that i am looking for is completely Full filled. Thanks so much for your help.
njammy 5-Nov-12 18:54pm    
In this case I should follow up with a note that the XMLReadMode.Auto eliminates another xml read issue surrounding the UTF8/16 encoding issue as well.
Sergey Alexandrovich Kryukov 5-Nov-12 19:48pm    
Silly... but what a catch! OK, a 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900