Logan
Logan

Reputation: 2515

Reading Escape Sequence in XML through Java

I am creating an XML file using Java and am then reading the data from it too. The data I am adding as text node contains <p> at several places, but as soon I try to read it, the string terminates on encountering <. What am I doing wrong? Would using escape sequence be helpful.?

Upvotes: 0

Views: 883

Answers (2)

WhiteFang34
WhiteFang34

Reputation: 72069

You could use StringEscapeUtils.escapeXml() from Apache Commons Lang to do escaping. However you shouldn't need to deal with escaping if you're using any library to read and write your XML. If you're constructing the XML entirely with your own strings then you should reconsider that approach.

Upvotes: 0

Tomas McGuinness
Tomas McGuinness

Reputation: 7689

You need to use entities for < and > as they are reserved characters. Use &lt; and &gt; to replace the angle brackets.

XML has other reserved characters like & also.

Upvotes: 1

Related Questions