问题描述
获取错误:路径中的非法字符
这有什么问题?
string xmlSR =
" ;< XmlDS>< table1>< phone> Value1< / phone>< name> jake< / name>< / table1>< / XmlDS>" ;;
myDataSet。 ReadXml(xmlSR,XmlReadMode.IgnoreSchema);
DataList5.DataSource = myDataSet;
DataList5.DataBind();
另外什么是将XML从绑定方法返回到
a web控件的最佳方法?
myDataSet.ReadXml(xy(),XmlReadMode。 IgnoreSchema);
我正在尝试这个,但它导致了没有数据源的错误,而且,
它只返回第一行:
public static string yt()
{
string conn =" Data
Source = .\\SQLEXPRESS; AttachDbFilename = | DataDirecto ry | \\ xn.mdf; Integrated
Security = True; User Instance = True" ;;
u sing(SqlConnection connection = new SqlConnection(conn))
{
connection.Open();
SqlCommand cmd = new SqlCommand(" select * from book2 for
xml path",connection);
cmd.CommandType = CommandType.Text;
XmlReader xr = cmd.ExecuteXmlReader ();
xr.MoveToContent();
return(xr.ReadOuterXml());
据推测,ReadXml不接受XML字符串,而是获取XML文件的路径
以上不是因为它有非法字符不能发生
的路径。
-
Bj?rn H?hrmann·mailto:bj **** @ hoehrmann.de ·
Weinh。海峡。 22·Telefon:+49(0)621/4309674·
68309曼海姆·PGP Pub。 KeyID:0xA4357E78·
据推测,ReadXml不接受XML字符串,而是获取XML文件的路径
以上不是因为它有非法字符不能发生
的路径。
-
Bj?rn H?hrmann·mailto:bj **** @ hoehrmann.de ·
Weinh。海峡。 22·Telefon:+49(0)621/4309674·
68309曼海姆·PGP Pub。 KeyID:0xA4357E78·
你应该传入一个带有URL的字符串作为ReadXml的第一个参数。
至少这是一个选项。你也可以传入一个XmlReader并基于你所展示的你想要做的事情,只需让你的
方法返回ExecuteXmlReader给你的读者,然后通过
读者阅读ReadXml
< http://msdn.microsoft.com/library/default.asp?url = / library / en-us / cpref /html/frlrfSystemDataDataSetClassReadXmlTopic4.asp>
< http://msdn.microsoft.com/library/default.asp?url = / library / en-us / cpref / html / frlrfSystemDataDataSetClassReadXmlTopic8.asp>
另一方面,你似乎有关系数据,然后你让
数据库转换并作为XML返回,然后你将XML加载到
DataSet(再次是数据的关系视图)。也许你只是体验和玩不同的API,但是如果不是我的话,我不知道为什么你让数据库完全返回XML,你可以简单地
进行正常的SQL查询并将结果加载到DataSet中。
-
Martin Honnen --- MVP XML
Getting error: Illegal characters in path
what''s wrong with this?
string xmlSR =
"<XmlDS><table1><phone>Value1</phone><name>jake</name></table1></XmlDS>";
myDataSet.ReadXml(xmlSR, XmlReadMode.IgnoreSchema);
DataList5.DataSource = myDataSet;
DataList5.DataBind();
Also, what''s the best way to return XML from a method for binding into
a web control?
myDataSet.ReadXml(x.y(), XmlReadMode.IgnoreSchema);
I''m trying this, but it''s resulting in error about no datasource, also,
its only returning the first row:
public static string yt()
{
string conn = "Data
Source=.\\SQLEXPRESS;AttachDbFilename=|DataDirecto ry|\\xx.mdf;Integrated
Security=True;User Instance=True";
using (SqlConnection connection = new SqlConnection(conn))
{
connection.Open();
SqlCommand cmd = new SqlCommand("select * from book2 for
xml path", connection);
cmd.CommandType = CommandType.Text;
XmlReader xr = cmd.ExecuteXmlReader();
xr.MoveToContent();
return(xr.ReadOuterXml());
Presumably ReadXml does not take a XML string but the path to a XML file
which the above is not since it has illegal characters that cannot occur
in a path.
--
Bj?rn H?hrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld.de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
Presumably ReadXml does not take a XML string but the path to a XML file
which the above is not since it has illegal characters that cannot occur
in a path.
--
Bj?rn H?hrmann · mailto:bj****@hoehrmann.de · http://bjoern.hoehrmann.de
Weinh. Str. 22 · Telefon: +49(0)621/4309674 · http://www.bjoernsworld..de
68309 Mannheim · PGP Pub. KeyID: 0xA4357E78 · http://www.websitedev.de/
You should pass in a string with a URL as the first argument to ReadXml.
At least that is one option. You can also pass in an XmlReader and based
on what you have shown that is what you want to do, simply let your
method return that reader that ExecuteXmlReader gives you, then pass
that reader to ReadXml
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataSetClassReadXmlTopic4.asp>
<http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemDataDataSetClassReadXmlTopic8.asp>
On the other hand you seem to have relational data, then you let the
data base convert and return that as XML, then you load the XML into a
DataSet (which is again a relational view of the data). Maybe you are
just experiementing and playing with the different APIs, but if not I am
not sure why you let the data base return XML at all, you can simply
make a normal SQL query and load that result in a DataSet.
--
Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
这篇关于ReadXML路径中的非法字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!