加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

System.Xml.XmlException: '=' is an unexpecte

发布时间:2020-12-15 23:48:28 所属栏目:百科 来源:网络整理
导读:今天碰到的一个问题,把string 解析成xml时,抛出异常,如下: 问题: An exception of type'System.Xml.XmlException' occurred and was caught. Type : System.Xml.XmlException,System.Xml,Version=4.0.0.0,Culture=neutral,PublicKeyToken= Message : '=

今天碰到的一个问题,把string 解析成xml时,抛出异常,如下:

问题:

An exception of type'System.Xml.XmlException' occurred and was caught.

Type : System.Xml.XmlException,System.Xml,Version=4.0.0.0,Culture=neutral,PublicKeyToken=

Message : '=' is an unexpected token. The expected token is ';'. Line X,position XXX.

或者

Message : The 'SPAN' start tag on line 1position 137 does not match the end tag of 'P'. Line X,position XXX.

Source : System.Xml

Help link :

LineNumber : X

LinePosition : XXX

SourceUri :

Data :System.Collections.ListDictionaryInternal

TargetSite : Void Throw(System.String,System.String[]) HResult : -2146232000

Stack Trace : atSystem.Xml.XmlTextReaderImpl.Throw(String res,String[] args)

at System.Xml.XmlTextReaderImpl.HandleEntityReference(BooleanisInAttributeValue,EntityExpandType expandType,Int32& charRefEndPos)

at System.Xml.XmlTextReaderImpl.ParseAttributeValueSlow(Int32 curPos,Char quoteChar,NodeData attr)

at System.Xml.XmlTextReaderImpl.ParseAttributes()

at System.Xml.XmlTextReaderImpl.ParseElement()

at System.Xml.XmlTextReaderImpl.ParseElementContent()

at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r)

at System.Xml.Linq.XContainer.ReadContentFrom(XmlReader r,LoadOptionso)

at System.Xml.Linq.XElement.ReadElementFrom(XmlReader r,LoadOptions o)

at System.Xml.Linq.XElement.Load(XmlReader reader,LoadOptions options)

at System.Xml.Linq.XElement.Parse(String text,LoadOptions options)


字符串是

<P><B>title</B></P>

<P> text 1 </P>

<P><B>description:</B></P>

<P>1. Provide<A href="http://dfafa&daffa&fasdf=1">rr</A></P>

<P>2. Reference <A href="http://dfafa&daffa&fasdf=1">ee</A>Guideline </P>

<P>3. Discuss</P>

<P>4. Schedulet </P>


原因是

A 标签在解析过程有问题,说是因为&符号。

或者 HTML 标签不匹配, 即:开始和结束标签不匹配。



解决方法:

1.针对特殊字符,例如:&, 需要转义

2.对于标签不匹配,例如: <span> 没有结束标签,需要手动修改。

可以使用工具XML Notepad,来确定出错位置,很方便。


如果在开发过程中,需要使用文本编辑器。

推荐一个工具:TinyMCE.

这个工具可以自动修复不正确的标签。出错率低。

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读