Priyanka Chaurishia
Priyanka Chaurishia

Reputation: 217

XML PCDATA and < and > encoding

I have to write some java code in xml file which will be autogenerated.

The dtd is third party so I cannot modify that.body tag declaration looks like that.

The code that I have to write looks something like in java : List <String > valueList = new ArrayList<>();

I have tried couple of things as below: List &#60;String &#62; valueList = new ArrayList<>();

List &lt;String &gt; valueList = new ArrayList<>();

But I am getting:org.xml.sax.SAXParseException; The content of elements must consist of well-formed character data or markup.

Any ideas what I am doing wrong .

I have to write java code in xml there is no workaround for that. If nothing works I have to drop generics use.

Any suggestion ?

Upvotes: 0

Views: 299

Answers (1)

C. M. Sperberg-McQueen
C. M. Sperberg-McQueen

Reputation: 25054

In your examples, you've escaped the first left angle bracket (and the first right angle bracket, which is nice and symmetrical but not necessary). But you haven't escaped the second. The string

List &#60;String &#62; valueList = new ArrayList<>();

is not allowed as PCDATA content, because it contains an unescaped left angle bracket. Try

List &#60;String &#62; valueList = new ArrayList&#60;&#62;();

Upvotes: 1

Related Questions