栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

sed异常/如果删除XML上的单词,则为其他条件

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

sed异常/如果删除XML上的单词,则为其他条件

不要尝试使用来编辑XML

sed
,它不是针对这种结构化数据而设计的。
sed
当有人在您原本不希望的空白处插入良性空格时,编辑XML的脚本总是会崩溃,而没有编辑XML的人则希望由于布局更改而导致损坏。

相反,我将使用XSLT:

<?xml version="1.0"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">  <!-- Identity template: just copy everything -->  <xsl:template match="@*|node()">    <xsl:copy>      <xsl:apply-templates select="@*|node()"/>    </xsl:copy>  </xsl:template>  <!-- special rule for version tags that include -SNAPSHOT and whose       parent tag has an artifactId subtag that contains scheduler-service -->  <xsl:template match="//version[contains(., '-SNAPSHOT') and not(contains(../artifactId, 'scheduler-service'))]">    <xsl:copy>      <!-- copy attributes -->      <xsl:apply-templates select="@*"/>      <!-- and only use the part of the node content before -SNAPSHOT -->      <xsl:value-of select="substring-before(., '-SNAPSHOT')"/>    </xsl:copy>  </xsl:template></xsl:stylesheet>

现在您可以使用例如

xsltproc foobar.xsl pom.xml

要么

xalan -in pom.xml -xsl foobar.xsl

根据您喜欢的XSLT处理器,foobar.xsl包含上面的样式表。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/412582.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号