System.Xml.XmlException: '=' is an unexpected token. The expected token is ';'

前端之家收集整理的这篇文章主要介绍了System.Xml.XmlException: '=' is an unexpected token. The expected token is ';'前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

问题:@H_403_1@

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

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

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

或者@H_403_1@

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

Source : System.Xml@H_403_1@

Help link : @H_403_1@

LineNumber : X@H_403_1@

LinePosition : XXX@H_403_1@

SourceUri : @H_403_1@

Data :System.Collections.ListDictionaryInternal@H_403_1@

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

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

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

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

at System.Xml.XmlTextReaderImpl.ParseAttributes()@H_403_1@

at System.Xml.XmlTextReaderImpl.ParseElement()@H_403_1@

at System.Xml.XmlTextReaderImpl.ParseElementContent()@H_403_1@

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

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

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

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

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


@H_403_1@

字符串是@H_403_1@

@H_403_1@

<P><B>title</B></P>@H_403_1@

<P> text 1 </P>@H_403_1@

<P><B>description:</B></P>@H_403_1@

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

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

<P>3. Discuss</P>@H_403_1@

<P>4. Schedulet </P>@H_403_1@

原因是:@H_403_1@

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

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


@H_403_1@


@H_403_1@

解决方法@H_403_1@

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

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

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


@H_403_1@

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

推荐一个工具:TinyMCE.@H_403_1@

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

猜你在找的XML相关文章