XML 中的特殊字符

XML中的特殊字符
(个人用于记录,只是为解决一时的问题)

1. Message         "An error occurredwhile parsing EntityName. Line 1, position 527."         string
//z 2011-12-29 9:54 AM is2120@csdn
事情的起源:
在传入xml文件给XmlDocument的时候总是出现Exception(异常)
//z 2011-12-29 9:54 AM is2120@csdn
-                              $exception         {"An error occurred while parsingEntityName. Line 1, position 527."}      System.Exception{System.Xml.XmlException}

-                              [System.Xml.XmlException]        {"An error occurred while parsingEntityName. Line 1, position 527."}                System.Xml.XmlException

-                              base      {"An error occurred while parsingEntityName. Line 1, position 527."}      System.SystemException{System.Xml.XmlException}

-                              base      {"An error occurred while parsingEntityName. Line 1, position 527."}      System.Exception{System.Xml.XmlException}

                                _className        Cannot fetch the value of field'_className' because information about the containing class is unavailable.    string

                                _data   Cannot fetch the value of field '_data'because information about the containing class is unavailable.                System.Collections.IDictionary

                                _dynamicMethods          Cannot fetch the value of field'_dynamicMethods' because information about the containing class isunavailable.   object

                                _exceptionMethod        Cannot fetch the value of field'_exceptionMethod' because information about the containing class isunavailable.   System.Reflection.MethodBase

                                _exceptionMethodString             Cannot fetch the value of field'_exceptionMethodString' because information about the containing class isunavailable.     string

                                _helpURL            Cannot fetch the value of field'_helpURL' because information about the containing class is unavailable.        string

                                _HResult              Cannot fetch the value of field'_HResult' because information about the containing class is unavailable.        int

                                _innerException               Cannot fetch the value of field'_innerException' because information about the containing class isunavailable.   System.Exception

                                _message           Cannot fetch the value of field'_message' because information about the containing class is unavailable.    string

                                _remoteStackIndex        Cannot fetch the value of field'_remoteStackIndex' because information about the containing class isunavailable.   int

                                _remoteStackTraceString             Cannot fetch the value of field'_remoteStackTraceString' because information about the containing class isunavailable.     string

                                _source                Cannot fetch the value of field'_source' because information about the containing class is unavailable.        string

                                _stackTrace        Cannot fetch the value of field'_stackTrace' because information about the containing class is unavailable.    object

                                _stackTraceString            Cannot fetch the value of field'_stackTraceString' because information about the containing class isunavailable.   string

                                _xcode Cannot fetch the value of field '_xcode'because information about the containing class is unavailable.        int

                                _xptrs   Cannot fetch the value of field '_xptrs'because information about the containing class is unavailable.        System.IntPtr

+                             Data       {System.Collections.ListDictionaryInternal}          System.Collections.IDictionary{System.Collections.ListDictionaryInternal}
//z 2011-12-29 9:54 AM is2120@csdn
2. 解决方案
2.1 xml中的特殊字符有5种:

<

小于号

>

大于号

&

&

'

'

单引号

"

"

双引号

在xml文件中将相应的特殊(转义)字符替换掉即可
//z 2011-12-29 9:54 AM is2120@csdn
2.2 但是可以不用自己造车轮的
微软提供了
SecurityElement.Escape
tagText = SecurityElement.Escape(tagText);


2.3 XmlTextWriter Class 在内部对此也做了相应的处理

//z 2011-12-29 9:54 AM is2120@csdn
2.4 含有特殊字符的也可以放在CDATA中进行处理(视情况而定)

转载于:https://www.cnblogs.com/IS2120/archive/2011/12/29/6745961.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值