java忽略转移i字符_Java:解析XML时忽略转义

我正在使用DocumentBuilder来解析XML文件.但是,项目规范要求在文本节点内使用& quot;等字符串.和& lt;从字面上返回,而不是解码为字符(“和

之前的类似问题Read escaped quote as escaped quote from xml收到了一个似乎特定于Apache的答案,而另一个答案似乎根本就没有做到它所说的那样.无论如何,我都喜欢被证明是错的,但是:)

供参考,这里有一些代码:

file = new File(fileName);

DocBderFac = DocumentBuilderFactory.newInstance();

DocBder = DocBderFac.newDocumentBuilder();

doc = DocBder.parse(file);

NodeList textElmntLst = doc.getElementsByTagName(text);

Element textElmnt = (Element) textElmntLst.item(0);

NodeList txts = textElmnt.getChildNodes();

String txt = ((Node) txts.item(0)).getNodeValue();

System.out.println(txt);

我想println()生成类似的东西

"3>2"

代替

"3>2"

这是目前发生的事情.

谢谢!

解决方法:

您可以将它们重新转换为xml编码形式

StringEscapeUtils.escapeXml(str);

标签:java,xml,escaping

来源: https://codeday.me/bug/20190701/1343065.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值