How can I escape double quotes in XML attributes values?

前端 未结 4 1445
盖世英雄少女心
盖世英雄少女心 2020-12-02 14:50

From the following trials


\">

Only the last one wor

相关标签:
4条回答
  • 2020-12-02 15:31

    The String conversion page on the Coder's Toolbox site is handy for encoding more than a small amount of HTML or XML code for inclusion as a value in an XML element.

    0 讨论(0)
  • 2020-12-02 15:33

    From the XML specification:

    To allow attribute values to contain both single and double quotes, the apostrophe or single-quote character (') may be represented as "'", and the double-quote character (") as """.

    0 讨论(0)
  • 2020-12-02 15:36

    A double quote character (") can be escaped as ", but here's the rest of the story...

    Double quote character must be escaped in this context:

    • In XML attributes delimited by double quotes:

      <EscapeNeeded name="Pete &quot;Maverick&quot; Mitchell"/>
      

    Double quote character need not be escaped in most contexts:

    • In XML textual content:

      <NoEscapeNeeded>He said, "Don't quote me."</NoEscapeNeeded>
      
    • In XML attributes delimited by single quotes ('):

      <NoEscapeNeeded name='Pete "Maverick" Mitchell'/>
      

      Similarly, (') require no escaping if (") are used for the attribute value delimiters:

      <NoEscapeNeeded name="Pete 'Maverick' Mitchell"/>
      

    See also

    • Simplified XML Escaping
    0 讨论(0)
  • 2020-12-02 15:41

    You can use &quot;

    0 讨论(0)
提交回复
热议问题