Click here to Skip to main content
12,505,881 members (50,774 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: .NET3.5 VB .NET VB.NET
Hi All,

I have a simple xml in database as below.

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


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.ReadXml(Doc.ToString)

Here
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 10:37am
Updated 5-Nov-12 10:44am
v3
Comments
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.
   
Try again -- now it's valid. (XML prolog is missing, but I don't think this is the problem.)
--SA

1 solution

Rate this: bad
 
good
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));
reader.Read();
 
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))
reader.Read()
Dim ds As System.Data.DataSet = New DataSet
        ds.ReadXml(reader, System.Data.XmlReadMode.Auto)
  Permalink  
v2
Comments
RaisKazi 5-Nov-12 17:15pm
   
My 5.
onenomi 5-Nov-12 17:34pm
   
Thanks
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.
onenomi 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.
   
Silly... but what a catch! OK, a 5.
--SA
Yakin79 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)

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160927.1 | Last Updated 5 Nov 2012
Copyright © CodeProject, 1999-2016
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