从xml文件中的字符串中读取“x”整数,并使用vbscript替换它

时间:2014-02-26 14:14:49

标签: xml vbscript

我有一个包含字符串和整数的xml文件,我需要替换其中一个字符串中的整数,我需要一次对多个文件执行此操作。 我已经设法找到节点并替换所有字符串,但不是特定的整数。

这是我的代码:

    on error resume next

    '***Edit for your needs.
    'Define what the values that you want to inject into the XML file.

     ServerIP = InputBox("Enter Server IP:", _
    "Create File")
     VersionNumber = InputBox("Enter version number:", _
    "Create File")

     'Create XMLDoc object
      Set xmlDoc = CreateObject("Microsoft.XMLDOM")

     '****Edit to your needs.
     'Here's where you would want to reference the file path to the configuration file.
     'load up the XML file and place it into xmldoc
      xmlDoc.load "C:\Users\danielc\Desktop\Viewer.xml"

  '***Edit to your needs.
  'Select the node we want to edit
    'The text IS case sensitive
    Set nServerIP = xmlDoc.selectsinglenode ("//Application/Url")
    Set nVersionNumber = xmlDoc.selectsinglenode ("//Application/Version")

'***Edit to your needs.
'Set the text node with the new value
nServerIP.text = ServerIP
nVersionNumber.text = VersionNumber
'nFtpServer.text = sFtpServer

'***Edit to your needs.
'Save the xml document with the new settings.
strResult = xmldoc.save("C:\Users\danielc\Desktop\Viewer.xml")

这是xml文件:

<?xml version="1.0"?>
<Application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"         xmlns:xsd="http://www.w3.org/2001/XMLSchema">`
    <Url>http://192.168.1.63/Shina/ThickClient_x64/Viewer/Viewer.zip</Url>
    <Version>3.0.44.0</Version>
</Application>

我需要更改标签中的IP地址。

任何人?

1 个答案:

答案 0 :(得分:0)

在本节中,将其替换为:

'Set the text node with the new value
nServerIP.text = ServerIP

有了这个:

'Set the text node with the new value
aURLParts = Split(nServerIP.text,"/")
nServerIP.text = Replace(nServerIP.text,aURLParts(2),ServerIP)