Reputation: 61
I am placing an SQL query(which contains < symbol) inside xml file and i am trying to read that query in a java program. But it is displaying the exception
"org.xml.sax.SAXParseException: The content of elements must consist of well-formed character data or markup."
can any one help me how to fix the above issue?
Upvotes: 3
Views: 1507
Reputation: 176936
Make use of CDATA
CDATA - (Unparsed) Character Data
CDATA stands for Character Data and it means that the data in between these tags includes data that could be interpreted as XML markup, but should not be
The term CDATA is used about text data that should not be parsed by the XML parser.
Characters like "<" and "&" are illegal in XML elements.
"<" will generate an error because the parser interprets it as the start of a new element.
"&" will generate an error because the parser interprets it as the start of an character entity.
Some text, like JavaScript code, contains a lot of "<" or "&" characters. To avoid errors script code can be defined as CDATA.
Everything inside a CDATA section is ignored by the parser.
Example:
<![CDATA[ select <abcddata> ]]>
Upvotes: 4
Reputation: 10303
< = >
> = <
These are the HTML entities and should be accepted
Upvotes: 3
Reputation: 425128
You need to escape using XML entities:
&
encode as &
<
encode as <
Technically, you don't need to escape the following, but it is common to do so:
>
encode as >
"
encode as "
'
encode as '
For more info, see this Wikipedia article for more
Upvotes: 6