Java - 从xml中删除标记 [英] Java - Removing tag from xml

查看:122
本文介绍了Java - 从xml中删除标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个xml,如下所示:

I have an xml, as follows:

<Row ss:Index="76" ss:AutoFitHeight="0" ss:Height="25">
   <Cell ss:Index="1" ss:MergeAcross="9" ss:StyleID="s38">
      <ss:Data ss:Type="String" xmlns="http://www.w3.org/TR/REC-html40">
          <Font html:Size="15" html:Face="Times New Roman" x:Family="Roman" html:Color="#000000">
            <B> ABCD </B>
          </Font>
       </ss:Data>
   </Cell>
</Row>

现在,我要删除< B>标签,但保留内容,ABCD在这里。或者有没有办法删除< B>使用java从整个XML文件。请帮忙。
谢谢。

Now, I want to remove the < B > tag, but retain the content, "ABCD" here. Or is there a way to remove the < B > from the whole XML file using java. Please help. Thanks.

推荐答案


  1. 使用 DOM4J SAX Parser

字体标记获取价值

<字体html:尺寸=15html:Face =Times New Romanx:Family =Romanhtml :颜色= #000000 >
< B> ABCD< / B>
< / Font>


  1. 从值<删除所有html标签

JSoup -way

Jsoup.parse(html).text();

String replaceAll-way:

String replaceAll-way:

replaceAll("\<(\/)?B\>","")




  1. 将新值设置为XML字体标记

这篇关于Java - 从xml中删除标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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