StAX 转义大于 (>)
我正在使用来自 http://stax.codehaus.org/ 的 vrsion 1.2.0 中的 StAX Streaming Api。 当我尝试将以下 xml 写入文件时,大于 char 的字符不会被转义。然而,小于似乎没有转义问题。
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();
输出(仅相关)是这样的:
<foo test="<foo>"
我也尝试使用 writeCharacters 方法 - 具有相同的结果。这是错误还是意图?有什么解决方法吗? (手动替换 > 会导致
replaceAll(">", ">");
'&' 本身被转义。
提前感谢您的帮助。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
基本上,这是因为您不需要转义
>
。它已经在做正确的事情了。Basically, it's because you don't need to escape
>
. It's already doing the right thing.