把DataTable中的数据拼接成XML时遇到的问题

错误信息:System.Web.Services.Protocols.SoapException: System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> System.Xml.XmlException: Name cannot begin with the '1' character, hexadecimal value 0x31. Line 1, position 918.
   at System.Xml.XmlTextReaderImpl.Throw(Exception e)
   at System.Xml.XmlTextReaderImpl.Throw(String res, String[] args)
   at System.Xml.XmlTextReaderImpl.ParseQName(Boolean isQName, Int32 startOffset, Int32& colonPos)
   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 BasInfomation.BasWebService.IsExsist(String xml, Int32 tag)
   at BasInfomation.BasWebService.GetBasInfo(Int32 tag, String basInfo)
   --- End of inner exception stack trace ---
   在 System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall)
   在 System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters)
   在 DataReport.WebInf.BasWebService.GetBasInfo(Int32 tag, String basInfo)
   在 DataReport.frmAutoUpdate.DataToXml(DataTable dtXml)
发生在:

错误解决:

 1、改头文件:sbXML.Append("<?xml version='1.0' encoding='utf-8'?>");为sbXML.Append("<?xml version='1.0' encoding='UTF-8'?>");

                  改过之后问题并没有解决,还是报该错误,纠结啊纠结啊。。。。

2、经过跟踪代码发现,并不是1中情况那样,而是取的数据中多了特殊符号(<  >等)如

    <MZZD>身体体表<10%烧伤</MZZD> <JBBM>T31.000</JBBM> <ZYZD>身体体表<10%烧伤</ZYZD>

    <和>号未经转义,就报上面的错误了,需要经过转义,下面是五个在XML文档中预定义好的实体:

&lt;
<
小于号
&gt;
>
大于号
&amp;
&
&apos;
'
单引号
&quot;
"
双引号
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值