Square brackets in XML?

13,944

Solution 1

There is probably a better solution. But this works:

]

as in:

<blah value="&#x005D;"></blah>

then again, so does (see Kirtan's answer):

<blah value="]"></blah> 

Solution 2

Square brackets do not need a specific notation in XML but they have a special meaning when used in XPath expressions for XSL transformations.

<root>
  <el attrib="[">[</el>
</root>

Solution 3

">" does not require to be escaped.

"]" does not require to be escaped.

"]]>" require to be escaped as part of the CDATA element.

Share:
13,944
Rahul Vyas
Author by

Rahul Vyas

Sr. iOS Developer, Gamer

Updated on July 29, 2022

Comments

  • Rahul Vyas
    Rahul Vyas almost 2 years

    In an XML document, how do I treat square brackets (] or [) ?

  • Ryan Rodemoyer
    Ryan Rodemoyer almost 11 years
    Funny, your answer is a direct copy from webdeveloper.com/forum/…