<分区>
我有一个包含一些 HTML 标签的 XML 文件。我想保留 XML 标签但删除 HTML 标签。例如在下面的结构中
<xml_tag_parent>
<xml_tag_child>
Some text here <p> some parag here </p>
</xml_tag_child>
</xml_tag_parent>
我想得到:
<xml_tag_parent>
<xml_tag_child>
Some text here some parag here
</xml_tag_child>
</xml_tag_parent>
事先不知道xml标签是什么。 另请注意,HTML 标记可能是嵌套的,所以我不能只获取节点的值。例如在下面的 xml 文档中:
<description id="description">
<heading id="h-0001" level="1">CROSS REFERENCE</heading>
<p id="p-0002" num="0001">The Paragraph </p>
<claim attr="someAttr"> abcs </claim>
<claim attr="2">
<p> this is another paragraph <b>with some bold things</b> </p>
</claim>
</description id="description">
我想得到:
<description id="description">
CROSS REFERENCE The Paragraph
<claim attr="someAttr"> abcs </claim>
<claim attr="2">
this is another paragraph with some bold things
</claim>
</description id="description">
我可以尝试对所有 HTML 标签进行硬编码,找到它们,然后删除它们。例如,我可以查找 < p > 标签并将其替换为空字符串,但这听起来不对,此外还有很多我需要覆盖的标签。是否有 Java 库或更好的方法来做到这一点?