Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Escaping Angle Brackets in XML in Eclipse / Android

Tags:

android

xml

If I want to to label some buttons with ">" and "<" symbols, what's the correct way to escape them out in the XML file? The presence of either ">" or "&" (as in "&gt") produces "invalid token" errors.

Thanks in advance.

like image 354
Peter Nelson Avatar asked Feb 12 '11 18:02

Peter Nelson


People also ask

How do you escape an angle bracket in XML?

The escape character for XML is the ampersand, &. The other dangerous character is the left angle bracket, the “less than,” <. Mostly to be symmetric, we also handle the right angle bracket, the “greater than,” >, similarly.

Can you use brackets in XML?

Note: The square brackets ( [ ] ) in the Edit Element dialog box represent XML opening and closing tags. To type a square bracket in the text of your design, use the following codes: &left; for “[“ or &right; for “]”. Select the XML element for which you want to edit the text content in the XML Tree.

Are square brackets allowed in XML?

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


1 Answers

Either specify those characters like this:

< = &lt; > = &gt; 

Or use a CDATA section and put those characters inside:

<![CDATA[<]]> <![CDATA[>]]> 
like image 137
Brian Showalter Avatar answered Sep 23 '22 18:09

Brian Showalter