zoukankan      html  css  js  c++  java
  • XML中的非法字符转化成实体

    问题
    如果XML有非法字符比如 "·",或者HTML标签<br/>。XML在解析的过程中就会出错。就无法正常解析,或者把xml反射成实体。
    有些字符,像(<)这类的,对HTML标准通用标记语言下的一个应用)来说是有特殊意义的,所以这些字符是不允许在文本中使用的。要在HTML中显示(<)这个字符,我们就必须使用实体字符。
    解决的办法
    如果这些非法字符或者HTML标签不是我们需要的可以用striing.Replace("非法字符","")把它替换为空。
    如果这些字符是必须的。我们可以替换成对应的实体。
    实体参考
     
     

    1实体字符

    一些字符在 HTML 中是预留的,拥有特殊的含义,比如小于号‘<’用于定义 HTML 标签的开始。如果我们希望浏览器正确地显示这些字符,我们必须在 HTML 源码中插入字符实体。
    字符实体有三部分:一个和号‘&’和一个实体名称(或者一个‘#’ 和一个实体编号),以及一个分号‘;’。
    要在 HTML 文档中显示小于号,我们需要这样写:&lt; 或者‘<’最后的效果则是<
    使用实体名称而不是实体编号的好处在于,名称相对来说更容易记忆。而这么做的坏处是,并不是所有的浏览器都支持最新的实体名称,然而几乎所有的浏览器对实体编号的支持都很好。
    注意:实体对大小写敏感。 

    2ASCI

    结果
    描述
    实体名称
    实体编号
    "
    quotation mark
    &quot;
    "
    '
    apostrophe
    &apos;
    '
    &
    ampersand
    &amp;
    &
    <
    less-than
    &lt;
    <
    >
    greater-than
    &gt;
    >

    3符号实体编辑

    结果
    描述
    实体名称
    实体编号
      
    non-breaking space
    &nbsp;
     
    ¡
    inverted exclamation mark
    &iexcl;
    ¡
    cent
    &cent;
    ¢
    pound
    &pound;
    £
    ¤
    currency
    &curren;
    ¤
    yen
    &yen;
    ¥
    |
    broken vertical bar
    &brvbar;
    ¦
    §
    section
    &sect;
    §
    ¨
    spacing diaeresis
    &uml;
    ¨
    ©
    copyright
    &copy;
    ©
    a
    feminine ordinal indicator
    &ordf;
    ª
    «
    angle quotation mark (left)
    &laquo;
    «
    ¬
    negation
    &not;
    ¬
      
    soft hyphen
    &shy;
     
    ®
    registered trademark
    &reg;
    ®
    ˉ
    spacing macron
    &macr;
    ¯
    °
    degree
    &deg;
    °
    ±
    plus-or-minus
    &plusmn;
    ±
    2
    superscript 2
    &sup2;
    ²
    3
    superscript 3
    &sup3;
    ³
    spacing acute
    &acute;
    ´
    μ
    micro
    &micro;
    µ
    paragraph
    &para;
    ·
    middle dot
    &middot;
    ·
    ¸
    spacing cedilla
    &cedil;
    ¸
    1
    superscript 1
    &sup1;
    ¹
    o
    masculine ordinal indicator
    &ordm;
    º
    »
    angle quotation mark (right)
    &raquo;
    »
    ¼
    fraction 1/4
    &frac14;
    ¼
    ½
    fraction 1/2
    &frac12;
    ½
    ¾
    fraction 3/4
    &frac34;
    ¾
    ¿
    inverted question mark
    &iquest;
    ¿
    ×
    multiplication
    &times;
    ×
    ÷
    division
    &divide;
    ÷

    4字符实体编辑

    结果
    描述
    实体名称
    实体编号
    à
    capital a, grave accent
    &Agrave;
    À
    á
    capital a, acute accent
    &Aacute;
    Á
    Â
    capital a, circumflex accent
    &Acirc;
    Â
    Ã
    capital a, tilde
    &Atilde;
    Ã
    Ä
    capital a, umlaut mark
    &Auml;
    Ä
    Å
    capital a, ring
    &Aring;
    Å
    Æ
    capital ae
    &AElig;
    Æ
    Ç
    capital c, cedilla
    &Ccedil;
    Ç
    è
    capital e, grave accent
    &Egrave;
    È
    é
    capital e, acute accent
    &Eacute;
    É
    ê
    capital e, circumflex accent
    &Ecirc;
    Ê
    Ë
    capital e, umlaut mark
    &Euml;
    Ë
    ì
    capital i, grave accent
    &Igrave;
    Ì
    í
    capital i, acute accent
    &Iacute;
    Í
    Î
    capital i, circumflex accent
    &Icirc;
    Î
    Ï
    capital i, umlaut mark
    &Iuml;
    Ï
    D
    capital eth, Icelandic
    &ETH;
    Ð
    Ñ
    capital n, tilde
    &Ntilde;
    Ñ
    ò
    capital o, grave accent
    &Ograve;
    Ò
    ó
    capital o, acute accent
    &Oacute;
    Ó
    Ô
    capital o, circumflex accent
    &Ocirc;
    Ô
    Õ
    capital o, tilde
    &Otilde;
    Õ
    Ö
    capital o, umlaut mark
    &Ouml;
    Ö
    Ø
    capital o, slash
    &Oslash;
    Ø
    ù
    capital u, grave accent
    &Ugrave;
    Ù
    ú
    capital u, acute accent
    &Uacute;
    Ú
    Û
    capital u, circumflex accent
    &Ucirc;
    Û
    ü
    capital u, umlaut mark
    &Uuml;
    Ü
    Y
    capital y, acute accent
    &Yacute;
    Ý
    T
    capital THORN, Icelandic
    &THORN;
    Þ
    ß
    small sharp s, German
    &szlig;
    ß
    à
    small a, grave accent
    &agrave;
    à
    á
    small a, acute accent
    &aacute;
    á
    a
    small a, circumflex accent
    &acirc;
    â
    ã
    small a, tilde
    &atilde;
    ã
    ä
    small a, umlaut mark
    &auml;
    ä
    å
    small a, ring
    &aring;
    å
    æ
    small ae
    &aelig;
    æ
    ç
    small c, cedilla
    &ccedil;
    ç
    è
    small e, grave accent
    &egrave;
    è
    é
    small e, acute accent
    &eacute;
    é
    ê
    small e, circumflex accent
    &ecirc;
    ê
    ë
    small e, umlaut mark
    &euml;
    ë
    ì
    small i, grave accent
    &igrave;
    ì
    í
    small i, acute accent
    &iacute;
    í
    î
    small i, circumflex accent
    &icirc;
    î
    ï
    small i, umlaut mark
    &iuml;
    ï
    e
    small eth, Icelandic
    &eth;
    ð
    ñ
    small n, tilde
    &ntilde;
    ñ
    ò
    small o, grave accent
    &ograve;
    ò
    ó
    small o, acute accent
    &oacute;
    ó
    ô
    small o, circumflex accent
    &ocirc;
    ô
    õ
    small o, tilde
    &otilde;
    õ
    ö
    small o, umlaut mark
    &ouml;
    ö
    ø
    small o, slash
    &oslash;
    ø
    ù
    small u, grave accent
    &ugrave;
    ù
    ú
    small u, acute accent
    &uacute;
    ú
    û
    small u, circumflex accent
    &ucirc;
    û
    ü
    small u, umlaut mark
    &uuml;
    ü
    y
    small y, acute accent
    &yacute;
    ý
    t
    small thorn, Icelandic
    &thorn;
    þ
    ÿ
    small y, umlaut mark
    &yuml;
    ÿ
    显示结果
    描述
    实体名称
    实体编号
      
    空格
    &nbsp;
     
    <
    小于号
    <
    << p=""><!--
    >
    大于号
    >
    >
    &
    和号
    &amp;
    &
    "
    引号
    &quot;
    "
    '
    撇号
    &apos; (IE不支持)
    '
    &cent;
    ¢
    &pound;
    £
    人民币
    &yen;
    ¥
               
  • 相关阅读:
    【总结】Centos中,Kerberos安装
    Go语言mgo
    Go语言mgo
    理解 Serenity,Part-1:深度抽象
    ZCash零知识证明
    零知识证明(Zero-Knowledge Proof)原理详解:非交互式证明实现自动验证防止作假
    tf.shape(x)、x.shape、x.get_shape()函数解析(最清晰的解释)
    Java生成(m.n)之间的随机数
    tf.cond()函数解析(最清晰的解释)
    OpenStack Blazar 架构解析与功能实践
  • 原文地址:https://www.cnblogs.com/sunxi/p/4208193.html
Copyright © 2011-2022 走看看