Represent space and tab in XML tag

前端 未结 8 1414

How to represent space and tab in XML tag. Is there any special characters for them to represent.

相关标签:
8条回答
  • 2020-11-29 05:22

    I think you could use an actual space or tab directly in XML document, but if you are looking for special characters to represent them so that text processors can't mess them up, then it's:

    space =  
    tab   = 	
    
    0 讨论(0)
  • 2020-11-29 05:24

    I had the same issue and none of the above answers solved the problem, so I tried something very straight-forward: I just putted in my strings.xml \n\t

    The complete String looks like this <string name="premium_features_listing_3">- Automatische Aktualisierung der\n\tDatenbank</string>

    Results in:

    • Automatische Aktualisierung der

      Datenbank

    (with no extra line in between)

    Maybe it will help others. Regards

    0 讨论(0)
  • 2020-11-29 05:30

    Work for me

    \n = &#xA;
    \r = &#xD;
    \t = &#x9;
    space = &#x20;
    

    Here is an example on how to use them in XML

    <KeyWord name="hello&#x9;" />
    
    0 讨论(0)
  • 2020-11-29 05:43

    For me, to make it work I need to encode hex value of space within CDATA xml element, so that post parsing it adds up just as in the htm webgae & when viewed in browser just displays a space!. ( all above ideas & answers are useful )

    <my-xml-element><![CDATA[&#x20;]]></my-xml-element>
    
    0 讨论(0)
  • 2020-11-29 05:45

    You cannot have spaces and tabs in the tag (i.e., name) of an XML elements, see the specs: http://www.w3.org/TR/REC-xml/#NT-STag. Beside alphanumeric characters, colon, underscore, dash and dot characters are allowed in a name, and the first letter cannot be a dash or a dot. Certain unicode characters are also permitted, without actually double-checking, I'd say that these are international letters.

    0 讨论(0)
  • 2020-11-29 05:48

    New, expanded answer to an old, commonly asked question...

    Whitespace in XML Component Names

    Summary: Whitespace characters are not permitted in XML element or attribute names.

    Here are the main Unicode code points related to whitespace:

    • #x0009 CHARACTER TABULATION
    • #x0020 SPACE
    • #x000A LINE FEED (LF)
    • #x000D CARRIAGE RETURN (CR)
    • #x00A0 NO-BREAK SPACE
    • [#x2002-#x200A] EN SPACE through HAIR SPACE
    • #x205F MEDIUM MATHEMATICAL SPACE
    • #x3000 IDEOGRAPHIC SPACE

    None of these code points are permitted by the W3C XML BNF for XML names:

    NameStartChar ::= ":" | [A-Z] | "_" | [a-z] | [#xC0-#xD6] | [#xD8-#xF6] |
                      [#xF8-#x2FF] | [#x370-#x37D] | [#x37F-#x1FFF] |
                      [#x200C-#x200D] | [#x2070-#x218F] | [#x2C00-#x2FEF] |
                      [#x3001-#xD7FF] | [#xF900-#xFDCF] | [#xFDF0-#xFFFD] |
                      [#x10000-#xEFFFF]
    NameChar      ::= NameStartChar | "-" | "." | [0-9] | #xB7 | [#x0300-#x036F] |
                      [#x203F-#x2040]
    Name          ::= NameStartChar (NameChar)*
    

    Whitespace in XML Content (Not Component Names)

    Summary: Whitespace characters are, of course, permitted in XML content.

    All of the above whitespace codepoints are permitted in XML content by the W3C XML BNF for Char:

    Char ::= #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF]
    /* any Unicode character, excluding the surrogate blocks, FFFE, and FFFF. */
    

    Unicode code points can be inserted as character references. Both decimal &#decimal; and hexadecimal &#xhex; forms are supported.

    • Hexadecimal  Decimal  Unicode Name
    • &#x09;   or   &#09;     CHARACTER TABULATION
    • &#x0A;   or   &#10;     LINE FEED (LF)
    • &#x0D;   or   &#13;     CARRIAGE RETURN (CR)
    • &#x20;   or   &#32;     SPACE
    • &#xA0;   or   &#160;   NO-BREAK SPACE
    0 讨论(0)
提交回复
热议问题