将xml加载到字符串时路径中的非法字符错误 [英] Illegal Characters in Path error while loading xml to string

查看:96
本文介绍了将xml加载到字符串时路径中的非法字符错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我在数据库中有一个简单的xml,如下所示.

Hi All,

I have a simple xml in database as below.

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



每当我将其另存为文件放在桌面上,然后加载到数据集中时,我都会自动创建数据表.

但是,如果我将其加载到字符串中并传递给它进行读取,则会收到一条错误消息,内容为"Illegal Characters in Path"

我使用的代码是



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)



在这里
Sbill是我的数据集
Rawxmlstr是我的字符串

关于如何消除此错误的任何想法,将不胜感激.



Here
Sbill is my dataset
Rawxmlstr is my string

Any Idea as of how to eliminate this error would be greatly appreciated.

推荐答案

您问题中的XML有效.

您遇到的问题是因为您尝试的XMLDoc代码期望包含xml的文件路径,而您传入​​的是XML字符串内容本身.

至于解决方案,请在下面查看我的示例,该示例有效:

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);



更新:对不起,我后来才意识到您的问题是VB:



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)


这篇关于将xml加载到字符串时路径中的非法字符错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆