elyan
elyan

Reputation: 23

StAX escaping of greater than (>)

I am using the StAX Streaming Api in vrsion 1.2.0 from http://stax.codehaus.org/. When I'm trying to write the following xml to a file the greater than char is not escaped. However lesser than does not seem to have a problem with escaping.

out = new FileOutputStream("foo.xml");
XMLOutputFactory factory = XMLOutputFactory.newInstance();
XMLStreamWriter writer = factory.createXMLStreamWriter(out);
writer.writeStartDocument();
writer.writeStartElement("foo");
writer.writeAttribute("test", "<foo>");
writer.writeEndElement();
writer.writeEndDocument();
writer.flush();
writer.close();
out.close();

The output (relevant only) is this:

<foo test="&lt;foo>"

I've also tried to use the writeCharacters method - with the same result. Is this a bug or intention? Is there any workaround? (Replacing > manually by

replaceAll(">", "&gt;");

results in the '&' getting escaped itself.

Thanks for any help in advance.

Upvotes: 2

Views: 1537

Answers (1)

Jon Skeet
Jon Skeet

Reputation: 1501586

Basically, it's because you don't need to escape >. It's already doing the right thing.

Upvotes: 7

Related Questions