Help needed asap,
Hi all i want to know whether it is possible to replace values of a
node or a child node(meaning a value of a tag) of one file to another
file.Both the files are of XML format and i want to do it with vb
script...

Eg: <Ip > some value </Ip> this is of the first file

<Ip> another value </Ip> another file.

Re: Replacing Xml Node values with new Values by JHP

JHP
Mon Sep 18 11:47:56 CDT 2006

This should get you started:
(watch for word wrap)
NB*: This has not been tested

Set objDOM = CreateObject("MSXML2.DOMDocument")
objDOM.Async = False
objDOM.ValidateOnParse = False
objDOM.ResolveExternals = False
objDOM.PreserveWhiteSpace = False

If objDOM.Load("C:\test.xml") Then
objNode = objDOM.DocumentElement
strNotes = objNode.SelectSingleNode("Notes")
strFiles = objNode.SelectSingleNode("Files")

If objDOM.Load("C:\test2.xml") Then
objNode = objDOM.DocumentElement
objNode.SelectSingleNode("Computers").SetAttribute("UpdateAll", "TRUE")
objNode.ReplaceChild(strNotes, objNode.SelectSingleNode("Notes"))
objNode.ReplaceChild(strFiles, objNode.SelectSingleNode("Files"))
objDOM.Save("C:\test3.xml")
End If
End If
Set objDOM = Nothing

"Chacko" <jacobneroth@gmail.com> wrote in message
news:1158581224.451716.26030@m73g2000cwd.googlegroups.com...
> Help needed asap,
> Hi all i want to know whether it is possible to replace values of a
> node or a child node(meaning a value of a tag) of one file to another
> file.Both the files are of XML format and i want to do it with vb
> script...
>
> Eg: <Ip > some value </Ip> this is of the first file
>
> <Ip> another value </Ip> another file.
>



Re: Replacing Xml Node values with new Values by JHP

JHP
Mon Sep 18 11:55:49 CDT 2006

Just to keep the naming convention accurate - change the strNotes to
objNotes and strFiles to objFiles...

If you need any more help - just respond to the newsgroup - myself or
someone else is sure to respond.

Cheers!

"JHP" <goawayspam@GFY.com> wrote in message
news:enXXEI02GHA.4636@TK2MSFTNGP06.phx.gbl...
> This should get you started:
> (watch for word wrap)
> NB*: This has not been tested
>
> Set objDOM = CreateObject("MSXML2.DOMDocument")
> objDOM.Async = False
> objDOM.ValidateOnParse = False
> objDOM.ResolveExternals = False
> objDOM.PreserveWhiteSpace = False
>
> If objDOM.Load("C:\test.xml") Then
> objNode = objDOM.DocumentElement
> strNotes = objNode.SelectSingleNode("Notes")
> strFiles = objNode.SelectSingleNode("Files")
>
> If objDOM.Load("C:\test2.xml") Then
> objNode = objDOM.DocumentElement
> objNode.SelectSingleNode("Computers").SetAttribute("UpdateAll", "TRUE")
> objNode.ReplaceChild(strNotes, objNode.SelectSingleNode("Notes"))
> objNode.ReplaceChild(strFiles, objNode.SelectSingleNode("Files"))
> objDOM.Save("C:\test3.xml")
> End If
> End If
> Set objDOM = Nothing
>
> "Chacko" <jacobneroth@gmail.com> wrote in message
> news:1158581224.451716.26030@m73g2000cwd.googlegroups.com...
>> Help needed asap,
>> Hi all i want to know whether it is possible to replace values of a
>> node or a child node(meaning a value of a tag) of one file to another
>> file.Both the files are of XML format and i want to do it with vb
>> script...
>>
>> Eg: <Ip > some value </Ip> this is of the first file
>>
>> <Ip> another value </Ip> another file.
>>
>
>



Re: Replacing Xml Node values with new Values by JHP

JHP
Mon Sep 18 13:29:51 CDT 2006

I tested the following version:

old.xml
<LAC>
<Computers UpdateAll="FALSE">
<Notes>
Test Information Notes
</Notes>
<Files>
Test Information Files
</Files>
</Computers>
</LAC>

new.xml
<LAC>
<Computers UpdateAll="FALSE">
<Notes></Notes>
<Files></Files>
</Computers>
</LAC>

Set objDOM = CreateObject("MSXML2.DOMDocument")
objDOM.Async = False
objDOM.ValidateOnParse = False
objDOM.ResolveExternals = False
objDOM.PreserveWhiteSpace = False

If objDOM.Load("old.xml") Then
Set objNode = objDOM.DocumentElement
Set objComputers = objNode.SelectSingleNode("Computers")

If objDOM.Load("new.xml") Then
Set objNode = objDOM.DocumentElement
objNode.ReplaceChild objComputers, objNode.SelectSingleNode("Computers")
objNode.SelectSingleNode("Computers").SetAttribute "UpdateAll", "TRUE"
objDOM.Save("new.xml")
End If
Set objFiles = Nothing
Set objNotes = Nothing
Set objNode = Nothing
End If
Set objDOM = Nothing
WScript.Echo "Completed"


"Chacko" <jacobneroth@gmail.com> wrote in message
news:1158581224.451716.26030@m73g2000cwd.googlegroups.com...
> Help needed asap,
> Hi all i want to know whether it is possible to replace values of a
> node or a child node(meaning a value of a tag) of one file to another
> file.Both the files are of XML format and i want to do it with vb
> script...
>
> Eg: <Ip > some value </Ip> this is of the first file
>
> <Ip> another value </Ip> another file.
>



Re: Replacing Xml Node values with new Values by Chacko

Chacko
Tue Sep 19 03:35:05 CDT 2006

Hey JHP thanx a lot dude... Will test it and let u know the same...
Thanx a bunch
JHP wrote:
> I tested the following version:
>
> old.xml
> <LAC>
> <Computers UpdateAll="FALSE">
> <Notes>
> Test Information Notes
> </Notes>
> <Files>
> Test Information Files
> </Files>
> </Computers>
> </LAC>
>
> new.xml
> <LAC>
> <Computers UpdateAll="FALSE">
> <Notes></Notes>
> <Files></Files>
> </Computers>
> </LAC>
>
> Set objDOM = CreateObject("MSXML2.DOMDocument")
> objDOM.Async = False
> objDOM.ValidateOnParse = False
> objDOM.ResolveExternals = False
> objDOM.PreserveWhiteSpace = False
>
> If objDOM.Load("old.xml") Then
> Set objNode = objDOM.DocumentElement
> Set objComputers = objNode.SelectSingleNode("Computers")
>
> If objDOM.Load("new.xml") Then
> Set objNode = objDOM.DocumentElement
> objNode.ReplaceChild objComputers, objNode.SelectSingleNode("Computers")
> objNode.SelectSingleNode("Computers").SetAttribute "UpdateAll", "TRUE"
> objDOM.Save("new.xml")
> End If
> Set objFiles = Nothing
> Set objNotes = Nothing
> Set objNode = Nothing
> End If
> Set objDOM = Nothing
> WScript.Echo "Completed"
>
>
> "Chacko" <jacobneroth@gmail.com> wrote in message
> news:1158581224.451716.26030@m73g2000cwd.googlegroups.com...
> > Help needed asap,
> > Hi all i want to know whether it is possible to replace values of a
> > node or a child node(meaning a value of a tag) of one file to another
> > file.Both the files are of XML format and i want to do it with vb
> > script...
> >
> > Eg: <Ip > some value </Ip> this is of the first file
> >
> > <Ip> another value </Ip> another file.
> >