java dom转义字符(java dom escape characters)

编程入门 行业动态 更新时间:2024-10-10 14:30:14
java dom转义字符(java dom escape characters)

我在使用DOM创建XML文件时遇到了转义字符的问题。 在结果文件中,我需要转义字符: & , < , > , " , ' 。生成XML文件后,DOM会自动转义字符& , < , > 。但字符"和'不会被转义。 如果我手动将这些字符更改为&quot; 和 在生成XML之前,DOM会转义符号& 。 结果是这样的: &amp;apos; 。

我该如何解决? 也许我可以设置为DOM以逃避符号"和'或者可能手动转义所有字符并禁用DOM自动转义。

I have a trouble with escaping characters while I create XML file with DOM. In result file I need to escape characters: &, <, >, ", '. After generating XML file DOM automatically escapes characters &, <, >. But characters " and ' are not escaped. If I change these characters manually to &quot; and &apos; before generating XML, DOM escapes the symbols &. And the result is like this: &amp;apos;.

How can I fix it? Maybe I can setup to DOM to escape the symbols " and ' or maybe it is possible to escape all characters manually and disable automatic escape by DOM.

最满意答案

我用解决方法解决了这个问题。 我在创建后重新打开文件并更改所需的所有符号。 也许它不是那么好的解决方案,但它运作正常。

I solved this problem with workaround. I reopen the file after creation and change the symbols all that I need. Maybe it is not so good solution, but it works fine.

更多推荐

本文发布于:2023-07-25 23:35:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1267890.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符   dom   java   escape   characters

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!