StAX 转义大于 (>)

发布于 2024-12-27 19:05:54 字数 829 浏览 1 评论 0原文

我正在使用来自 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="&lt;foo>"

我也尝试使用 writeCharacters 方法 - 具有相同的结果。这是错误还是意图?有什么解决方法吗? (手动替换 > 会导致

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

'&' 本身被转义。

提前感谢您的帮助。

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

无人问我粥可暖 2025-01-03 19:05:54

基本上,这是因为您不需要转义>。它已经在做正确的事情了。

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文