我在使用DOM创建XML文件时遇到了转义字符的问题。 在结果文件中,我需要转义字符: & , < , > , " , ' 。生成XML文件后,DOM会自动转义字符& , < , > 。但字符"和'不会被转义。 如果我手动将这些字符更改为" 和 在生成XML之前,DOM会转义符号& 。 结果是这样的: &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 " and ' before generating XML, DOM escapes the symbols &. And the result is like this: &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.
更多推荐
发布评论