Dataset.ReadXML 在路径中返回无效字符。为什么?
我正在使用 ReadXML
方法将字符串读入 DataSet
中。当我尝试这样做时,它返回路径错误中的无效字符。如果我在 IE 中将字符串保存为 xml 文件并打开,它会在 encoding="UTF-16"
行上引发错误,因此我认为这就是问题的原因。
有没有简单的方法来解决这个问题?它不应该能够处理 unicode 或 UTF-16 吗?
任何建议将不胜感激。使用 C# 和.Net 4
<?xml version="1.0" encoding="UTF-8" ?>
<iCall xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Rows>
<Row>
<Code />
<Title>Test Title</Title>
</Row>
</Rows>
</iCall>
I'm reading a string into a DataSet
using the ReadXML
method. When I try that it returns an Invalid Characters in the path error. if I save and open the string in IE as an xml file it throws an error on the encoding="UTF-16"
line so I assume that is the cause of the problem.
Is there a simple way to fix this? Shouldn't it be able to handle unicode or UTF-16?
Any suggestions would be much appreciated. Using C# & .Net 4
<?xml version="1.0" encoding="UTF-8" ?>
<iCall xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Rows>
<Row>
<Code />
<Title>Test Title</Title>
</Row>
</Rows>
</iCall>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我认为您可以尝试使用 ReadStartElement 前进到下一个节点并将整个表读入 DataSet。
I think you can try to use ReadStartElement to advance to the next node and read the whole table into DataSet.
此示例代码将解决该问题。
This sample code will fix the problem.
最好使用额外的行 XmlTextReader xtr = ... 并将 xtr 传递给 ReadXml 方法。
It is better to use an extra line XmlTextReader xtr = ... and pass xtr to ReadXml method.
DataSet.ReadXml(string) 需要文件路径而不< /em> 一个 xml 文档。因此,它尝试将您的 xml 文档解析为文件路径,
如果您只有 XML 运行时,则会失败,那么您可以这样做:
DataSet.ReadXml(string) expects a file path not an xml document. So it tries to parse your xml document as a filepath and fails
if you only have your XML runtime, then you can do like this: