Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Appending to an XML file

Reply
 
Old 08-18-2009   #1 (permalink)
Neil


 
 

Appending to an XML file

Hi

I'm trying to modify an XML file using vbscript; editing an item between 2
elements.

I've manged to get my script to delete the old entries, but whenever I try
and add my test entry between the selected elements, it adds the entry at the
very end of the XML file!

Option explicit
Dim oldnode, objXML, newXML, x, y
Set objXML = CreateObject("Microsoft.XMLDOM")

with objXML
.Load("machine.xml")
End with
' Find the node to be deleted
Set oldnode =
objXML.documentElement.selectSingleNode("//quarantineManager/actions")

with oldnode
.parentnode.removeChild(oldnode)
End with

Set newXML = objXML.createElement("New_Tag")

Set y = objXML.documentElement
Set x = y.getElementsByTagName("quarantineManager")
y.appendChild(newXML)

objXML.save ("machineNew.xml")

My System SpecsSystem Spec
Old 08-18-2009   #2 (permalink)
mr_unreliable


 
 

Re: Appending to an XML file

Neil wrote:
Quote:

> I've manged to get my script to delete the old entries, but whenever
I try
Quote:

> and add my test entry between the selected elements, it adds the entry at the
> very end of the XML file!
>
hi Neil,

Try using the "InsertBefore" method.

Or, rather than the delete+add approach, modify the node you have.

cheers, jw
____________________________________________________________

You got questions? WE GOT ANSWERS!!! ..(but, no guarantee
the answers will be applicable to the questions)
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Vista Appending Computer-name Network & Sharing
Appending permissions to Access control lists PowerShell
appending/writing to a file VB Script
invoke-expression not appending PowerShell
Problems with appending DNS suffix for name resolution Vista networking & sharing


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46