Reputation: 299
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 <
and >
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?
Upvotes: 4
Views: 21956
Reputation: 287745
<
is encoded as <
.
>
is encoded as >
.
"
is encoded as "
.
&
is encoded as &
.
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.
Upvotes: 14
Reputation: 943099
There are two ways to represent characters which have special meaning in XML (such as <
and >
) in an XML document.
A CDATA section can only be used in places where you could have a text node.
<foo><![CDATA[Here is some data including < and > (and &!) ]]></foo>
The caveat is that you can't include the sequence ]]>
as data in a CDATA section.
Entities can be used everywhere (except inside CDATA sections) and consist of &
, then an identifier, then ;
.
<foo>Here is some data including < and > (and &!)</foo>
I do know about
<
and>
but that isn't helpful.
It is how XML works. It is one of your only two options. It should not be a problem (if it is, then you need to explain why in your question).
Upvotes: 7