
它的工作正常,但是当有特殊字符时,如&或=它给出了一个错误.
我的XML字符串:
<SuggestedReadings> <Suggestion Text="Customer Centricity" link="http://wdp.wharton.upenn.edu/book/customer-centricity/?utm_source=Coursera&utm_medium=Web&utm_campaign=custcent" SuggBy="Pete Fader�s" /> <Suggestion Text="Global Brand Power" link="http://wdp.wharton.upenn.edu/books/global-brand-power/?utm_source=Coursera&utm_medium=Web&utm_campaign=glbrpower" SuggBy="barbara Kahn�s" /></SuggestedReadings>
我的代码是:
public class saveData(string strXml){ Xmldocument xmlDoc = new Xmldocument(); xmlDoc.LoadXml(CD.SRList);// here its giving error} 错误:
‘=’ is an unexpected token. The expected token is ‘;’. line 1,position 150.
完整错误是:
解决方法 您的文档缺少XML标头,这是必需的.此外,你没有正确地逃避&字符.System.Xml.XmlException was unhandled by user code HResult=-2146232000
Message=’=’ is an unexpected token. The expected token is ‘;’. line 1,
position 150. Source=System.Xml lineNumber=1 lineposition=150
SourceUri=”” StackTrace: at
System.Xml.XmlTextReaderImpl.Throw(Exception e) at
System.Xml.XmlTextReaderImpl.Throw(String res,String[] args) at
System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(String
expectedToken1,String expectedToken2) at
System.Xml.XmlTextReaderImpl.ThrowUnexpectedToken(Int32 pos,String
expectedToken1,String expectedToken2) at
System.Xml.XmlTextReaderImpl.HandleEntityReference(Boolean
isInAttributeValue,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.XmlTextReaderImpl.Read() at
System.Xml.XmlLoader.LoadNode(Boolean skipOverWhitespace) at
System.Xml.XmlLoader.LoadDocSequence(Xmldocument parentDoc) at
System.Xml.XmlLoader.Load(Xmldocument doc,XmlReader reader,Boolean
preserveWhitespace) at System.Xml.Xmldocument.Load(XmlReader
reader) at System.Xml.Xmldocument.LoadXml(String xml) at
ICA.LMS.Service.Controllers.adminCourseAPIController.SaveCourse(CourseDetails
CD) in d:\live
Projects\ICA_LMS\ICA_LMS_WebAPI\Controllers\adminCourseAPIController.cs:line
122 at lambda_method(Closure,Object,Object[] ) at
System.Web.http.Controllers.ReflectedhttpActionDescriptor.ActionExecutor.<>c__displayClass10.b__9(Object
instance,Object[] methodParameters) at
System.Web.http.Controllers.ReflectedhttpActionDescriptor.ActionExecutor.Execute(Object
instance,Object[] arguments) at
System.Web.http.Controllers.ReflectedhttpActionDescriptor.ExecuteAsync(httpControllerContext
controllerContext,IDictionary`2 arguments,CancellationToken
cancellationToken) InnerException:
尝试在XML文档之上添加它:
<?xml version="1.0" enCoding="UTF-8"?>
并且还替换&与& amp ;. (见list of characters to escape)
总结以上是内存溢出为你收集整理的c# – 无法将字符串转换为XML全部内容,希望文章能够帮你解决c# – 无法将字符串转换为XML所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)