Click here to Skip to main content
Rate this: bad
Please Sign up or sign in to vote.
See more: .NET3.5 VB.NET
Hi All,
I have a simple xml in database as below.

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.
Posted 5-Nov-12 11:37am
Edited 5-Nov-12 11:44am
CPallini at 5-Nov-12 16:42pm
Your simple XML doesn't look correct: last node should be </test>.
Vamshi Krishna Naidu at 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 at 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

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

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)
RaisKazi at 5-Nov-12 17:15pm
My 5.
onenomi at 5-Nov-12 17:34pm
Vamshi Krishna Naidu at 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.
onenomi at 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 at 5-Nov-12 19:48pm
Silly... but what a catch! OK, a 5.
Yakin79 at 5-Nov-14 14:17pm
Solution 1
Has solve my problem, thankyou very much

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

Advertise | Privacy | Mobile
Web04 | 2.8.150327.1 | Last Updated 5 Nov 2012
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100