批量修改XML文件 [英] Modify XML file in batch

查看:880
本文介绍了批量修改XML文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了,我不是超级熟悉使用FOR / F。如果该文件是静态的,并且具有我可以跳过,然后从拉条数据线的一组ammount的我可以修改它。我目前正在修改.xml文件。该文件将有不同的行ammounts,但总会有以下

Ok, so I'm not super familiar with using For /F. I can modify it if the file is static and has a set ammount of lines that i can skip and then pull data from. I'm currently trying to modify an .XML file. The file will have varying ammounts of lines, but will always have the following

< / SyncWindow>
  < / AutoSyncWindows>
  < SyncServiceConnections />
  &所述; DaysToRetainRecordedData> 90℃/ DaysToRetainRecordedData>
  < SyncRestartRequired>假LT; / SyncRestartRequired>
- < LastGroupsSynced>

&LT的价值; DaysToRetainRecordedData> 90°/ DaysToRetainRecordedData> 可能会有所不同,例如< D​​aysToRetainRecordedData> 30℃/ DaysToRetainRecordedData>

The value for <DaysToRetainRecordedData>90</DaysToRetainRecordedData> may differ, for example <DaysToRetainRecordedData>30</DaysToRetainRecordedData>

使用代币,这将是最有效的方式来搜索.XML文件该行并覆盖它下面的&LT; D​​aysToRetainRecordedData&GT; 0℃; / DaysToRetainRecordedData&GT;

Using tokens, what would be the most efficient way to search that .XML file for that line and overwrite it with the following <DaysToRetainRecordedData>0</DaysToRetainRecordedData>

,因为它们具有独特的服务器密钥,这将改变从机machine.So我需要能够找到该行和编辑该值为0我不能覆盖整个.XML文件。
有什么想法吗?如果FOR / F是不是要走的最有效的方法,我在需要时可以移动到VBS。但它必须从单纯的壳code调用,会使事情复杂一点。

I can not overwrite the entire .XML file as they have unique server keys that will vary from machine to machine.So I need to be able to find that line and edit the value to 0. Any thoughts? If For /F is not the most efficient way to go, I can move to VBS if need be. But it would have to be called from pure shellcode and would make things a bit more complex.

推荐答案

最优雅,灵活,安全的方式来做到这将是下载<一个href=\"http://www.microsoft.com/downloads/en/details.aspx?FamilyID=2fb55371-c94e-4373-b0e9-db4816552e41\"相对=nofollow> MSXSL.EXE ,然后使用一个微小的XSLT样式表只修改您在XML想要的值:

The most elegant, flexible and safe way to do this would be to download msxsl.exe and then use a tiny XSLT stylesheet to modify only the value you want in the 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>

调用的命令行上:

Call that on the command line with:

msxsl.exe input.xml DaysToRetainRecordedData.xsl –o output.xml newValue=0

命令行参数为newValue 将在XSL程序显示出来。

The command line parameter newValue will show up in the XSL program.

这篇关于批量修改XML文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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