Reputation: 23
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="<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(">", ">");
results in the '&' getting escaped itself.
Thanks for any help in advance.
Upvotes: 2
Views: 1537
Reputation: 1501586
Basically, it's because you don't need to escape >
. It's already doing the right thing.
Upvotes: 7