如何创建vbscript或批处理文件以覆盖现有的xml文件

时间:2012-05-21 20:39:28

标签: xml vbscript batch-file

我们的应用程序的一个用户在位置zean.xml中有一个名为C:\ProgramData\Secon\levrer\8.6.7\team\lead\Captain folder的xml文件。但现在我觉得我需要将以下内容替换为xml文件内容作为一种常态解决方法。我想写一下vbscript或bat文件,以便我可以给使用这个xml文件的用户。任何机构都可以为我提供vbscript代码或bat文件,用于使用以下内容重写xml文件

  <?xml version="1.0" standalone="yes" ?> 
 <TestSchema xmlns="http://tempuri.org/TestSchema.xsd">
  <UserZone>
  <Label>All</Label> 
  <ID>8c19c791-32d6-4ad1-8504-c3387b5a0096</ID> 
  </UserZone>
 <ZoneMgGrpCollection>
  <Owner>8c19c791-32d6-4ad1-8504-c3387b5a0096</Owner> 
  <MgGrpID>5f498b70-ee75-4ff0-8808-b9ba492b7f8a</MgGrpID> 
  </ZoneMgGrpCollection>
  </TestSchema>

1 个答案:

答案 0 :(得分:1)

只需将文本添加到新的XML文件中,然后将其复制到另一个文件上即可。 您既可以手动也可以通过脚本执行,但我不明白为什么您会通过脚本执行此操作,因为这显然是一次性操作。

Const ForReading = 1, ForWriting = 2, ForAppending = 8, CreateIfNeeded = true
Set fso = CreateObject("Scripting.FileSystemObject")
set tf=fso.OpenTextFile ("new.xml",ForWriting,CreateIfNeeded)
tf.write "<?xml version=""1.0"" standalone=""yes"" ?>  "
'repeat this for the other lines
tf.close
fso.CopyFile("new.xml", "C:\ProgramData\Secon\levrer\8.6.7\team\lead\Captain folder\",True)
相关问题