Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to encode '<' & '>' Symbols in XML

Since < & > as part of XML syntax. How to add these symbols as part of the data like

<Note>Have to have <> symbols</Note>

I have heard there are different types of data in which XML can be sent like CDATA etc, since character data parses each character it doesn't allow these symbols.

I do know about &lt; and &gt; but that isn't helpful.

Are there are any modes of data in which XML can be sent to avoid any tool recognizing the symbols?

like image 418
user1002782 Avatar asked Nov 29 '22 16:11

user1002782


1 Answers

< is encoded as &lt;.
> is encoded as &gt;.
" is encoded as &quot;.
& is encoded as &amp;.

Alternatively, you can pack the whole data in a CDATA section if it doesn't contain a CDATA section itself. If you're generating programatically, encoding each character is the better solution though.

Note that there is a plethora of XML libraries available for almost every language. Unless you want to learn about XML, I strongly recommend using an XML library instead of writing your own.

like image 181
phihag Avatar answered Dec 15 '22 09:12

phihag