批量修改XML文件
好的,所以我对使用For / F并不是很熟悉.我可以修改它,如果文件是静态的,并且有一组我可以跳过然后从中提取数据的行.我目前正在尝试修改.
XML文件.该文件将具有不同的线路,但始终具有以下内容
< / SyncWindow> < DaysToRetainRecordedData> 90< / DaysToRetainRecordedData>的值可以不同,例如< DaysToRetainRecordedData> 30< / DaysToRetainRecordedData> 使用令牌,搜索该行的.XML文件并使用以下< DaysToRetainRecordedData> 0< / DaysToRetainRecordedData>覆盖它的最有效方法是什么? 我无法覆盖整个.XML文件,因为它们具有因机器而异的唯一服务器密钥.所以我需要能够找到该行并将值编辑为0. 解决方法
最优雅,灵活和安全的方法是下载
msxsl.exe,然后使用一个小的XSLT样式表来仅修改XML中所需的值:
<!-- DaysToRetainRecordedData.xsl --> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:param name="newValue" select="0" /> <!-- this template copies your input XML unchanged --> <xsl:template match="node()|@*"> <xsl:copy> <xsl:apply-templates select="node()|@*" /> </xsl:copy> </xsl:template> <!-- this template changes one single value --> <xsl:template match="DaysToRetainRecordedData/text()"> <xsl:value-of select="$newValue" /> </xsl:template> </xsl:stylesheet> 在命令行上调用: msxsl.exe input.xml DaysToRetainRecordedData.xsl –o output.xml newValue=0 命令行参数newValue将显示在XSL程序中. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |