java - 从包含 vs 代码注释的 xml 文件中删除块
问题描述
我有这样的 xml 文件(10k 行):
<?xml version="1.0" encoding="UTF-8"?>
<Translations xmlns="http:...">
<customApplications>
<label><!-- Pricing Notifications --></label>
<name>TEAM_Tesla</name>
</customApplications>
<customApplications>
<label><!-- CRM --></label>
<name>TEAM_Tender</name>
</customApplications>
<customApplications>
<label>Actualization Portal</label>
<name>Actualization_Portal</name>
</customApplications>
我想删除包含注释的块(不仅是注释部分)
期望的输出:
<?xml version="1.0" encoding="UTF-8"?>
<Translations xmlns="http:...">
<customApplications>
<label>Actualization Portal</label>
<name>Actualization_Portal</name>
</customApplications>
解决方案
XSLT 喜欢
<xsl:stylesheet
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
version="1.0">
<xsl:template match="@* | node()">
<xsl:copy>
<xsl:apply-templates select="@* | node()"/>
</xsl:copy>
</xsl:template>
<xsl:template match="/*/*[descendant::comment()]"/>
</xsl:stylesheet>
将删除具有注释节点作为后代的根元素的任何子元素。您可以使用https://docs.oracle.com/javase/8/docs/api/javax/xml/transform/Transformer.html在 Java 中运行 XSLT 。
推荐阅读
- android - actionLayout 不显示在导航抽屉中
- android - 试图在列表视图的末尾加载更多项目
- batch-file - 检查驱动器是否有足够的空间进行备份
- android - 应用程序在模拟器上完美显示,但在设计预览中不显示?
- python - 如何从 colaboratory 下载此模型
- installshield - Installshield 2013 Installscript MSI:修复期间错误的 .msi 位置
- meteor - 流星每秒增加 DB 中的一些值
- css - Mixin 参数作为类名的一部分
- dependency-injection - Symfony4 - 如何将 TokenStorageInterface 传递给 EntityListener?
- jquery - 是否可以在 ajax 函数的数据列表中传递 django 模型对象?