解析EntityName时发生错误。第1行,位置844。 [英] An error occurred while parsing EntityName. Line1, position 844.

查看:1103
本文介绍了解析EntityName时发生错误。第1行,位置844。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我从以下代码块中得到以下异常。



解析EntityName时发生错误。第1行,第844位。





我试图将从表中检索到的数据集解析为数据集。



Hi All,

I have got the following exception from the below code block.

An error occurred while parsing EntityName. Line1, position 844.


I was trying to parse s set of data retrieved from table to a data set.

public DataSet BindMasterData(string xml)
        {
            DataSet ds = null;
            try
            {
                ds = new DataSet();
                TextReader txtReader = new StringReader(xml);
                XmlReader reader = new XmlTextReader(txtReader);
                ds.ReadXml(reader);
            }
            catch (Exception ex)
            {
                return new DataSet();
            }
            return ds;
        }





我已经找到了异常的原因,但我无法解决。在这种特殊情况下,字符串(从DB检索)包含一个特殊字符(&)。这导致例外。我怎么解决它。任何有关这方面的帮助都会很棒。



谢谢&问候

Sebastian



I have figured out the reason for the exception, but I couldn't solve it. In this particular situation, the string(which is retrieved from DB) contains a special character (&). That causes exception. How I can solve it. Any help on this would be great.

Thanks & Regards
Sebastian

推荐答案

你需要正确格式化你的xml。一个&应该是& amp;因此,在将xml传递给此函数时,请正确格式化。



如果由于某种原因你无法控制传递给你的xml,你可以关闭字符检查做这样的事情:

You need to format your xml properly. An & should actually be & So, format the xml properly when you pass it into this function.

If for some reason you cannot control the xml getting passed to you, you can turn off character checking by doing something like this:
string filePath = @"You file dirtest.xml"; XmlReaderSettings xrs = new XmlReaderSettings(); xrs.CheckCharacters = false; using (XmlReader reader = XmlReader.Create(filePath, xrs)) { while (reader.ReadToFollowing("Content")) {} } - See more at: http://www.debugdotnet.com/xmlreader-read-special-unicode-use-xmlreadersettings-checkcharacters.html#sthash.HrQMOFOd.dpuf



http:// www.debugdotnet.com/xmlreader-read-special-unicode-use-xmlreadersettings-checkcharacters.html [ ^ ]



但是,最好的选择是发送正确形成xml。


http://www.debugdotnet.com/xmlreader-read-special-unicode-use-xmlreadersettings-checkcharacters.html[^]

However, the best option is to send in properly formed xml.


这篇关于解析EntityName时发生错误。第1行,位置844。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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