在解析实体名称出现错误。 1号线,位置844 [英] An error occurred while parsing EntityName. Line1, position 844
本文介绍了在解析实体名称出现错误。 1号线,位置844的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有从下面的代码块下面的异常。
I have got the following exception from the below code block.
在解析实体名称出现错误。线路1,位置844。
我试图解析S设定从表中检索到的数据集的数据。
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中检索)包含特殊字符(安培)。这会导致异常。我怎样才能解决这个问题。 。任何帮助将是巨大的。
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元素无效:
" "
' '
< <
> >
& &
public static string UnescapeXMLValue(string xmlString)
{
if (xmlString == null)
throw new ArgumentNullException("xmlString")
return xmlString.Replace("'", "'").Replace(""", "\"").Replace(">", ">").Replace("<", "<").Replace("&", "&");
}
public static string EscapeXMLValue(string xmlString)
{
if (xmlString == null)
throw new ArgumentNullException("xmlString")
return xmlString.Replace("'","'").Replace( "\"", """).Replace(">",">").Replace( "<","<").Replace( "&","&");
}
这篇关于在解析实体名称出现错误。 1号线,位置844的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文