StAX XML Parser没有转义单引号(&) [英] StAX XML Parser not escaping single quote (')

查看:307
本文介绍了StAX XML Parser没有转义单引号(&)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用StAX解析器来读取大型XML文件并剥离一些元素/属性并编写XML文件

We are using StAX parser to read the large XML files and strip off some of the elements/attributes and write the XML file

源XML文件是有效的XML文件即具有所有XML特殊字符(< > '& )使用各自的XML版本进行转义(& lt; & gt; &'; & quot; & amp;

The source XML file is valid XML file i.e. have all XML Special characters(<,>,',",&) escaped with respective XML versions(&lt;, &gt;, &apos;, &quot;, &amp;)

当StaX解析器时在输出文件中写下这些特殊字符,它正在转义< > & ; 字符但不是'字符,即在输出文件中我们可以看到'字符,虽然输入文件有转义版本

When StaX parser writing these special characters in the output file it is escaping <,>,& characters but not'," characters i.e in output file we can see the '," characters, although the input file have its escaped versions

在将输出发送到StaX解析器 String.replaceAll(',&;)方法替换> writeAttribute 方法

I have tried to replace using String.replaceAll("'","&apos;") method before sending the output to StaX parser writeAttribute method

但是因为StAX解析器已经转义了<,>,&字符输出显示为& amp;

But as StAX parser already escaping <,>,& character the output is showing as &amp;apos;

你可以让我知道是否有任何配置/ stAX解析器API中的utiltity来解决StAX解析器中的这个问题?

Can you let me kow is there any configuration/utiltity in StAX parser API to solve this issue in StAX parser?

或者,使用另一个解决这个问题的XML编写器工具的其他任何建议?

Or, alternatively, any other suggestions to use another XML writer tool which solves this problem?

推荐答案

如果单引号出现在由单引号括起的属性值中,则只需要对其进行转义。除此之外没有任何理由逃脱它们。

Single quotes only need to be escaped if they occur in an attribute value enclosed by single quotes. There's not really any reason to escape them otherwise.

这篇关于StAX XML Parser没有转义单引号(&amp;)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆