• 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中进行处理(视情况而定)
  • 相关阅读:
    NetCore物联网平台 4
    NetCore物联网平台 3
    NetCore物联网平台 2
    NetCore物联网平台 1
    阿里云IoT 8:待更新
    阿里云IoT 7:待更新
    阿里云IoT 6:待更新
    阿里云IoT 5:待更新
    阿里云IoT 4:数据解析
    svg 实现半环形进度条
  • 原文地址:https://www.cnblogs.com/IS2120/p/6745961.html
Copyright © 2020-2023  润新知