Wrox Programmer Forums
Go Back   Wrox Programmer Forums > XML > XML
|
XML General XML discussions.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the XML section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 21st, 2005, 02:32 AM
Registered User
 
Join Date: Mar 2005
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default update xml file using vbs

I am a newbie to XML.
This is my small vbs to add new names into an existing xml file.

Set objXMLDoc = CreateObject("Microsoft.XMLDOM")
objXMLDoc.async = False
objXMLDoc.load("names.xml")

Dim objCurrNode, objNewNode, objNewText
Set objNewNode = objXMLDoc.createElement("name")
Set objNewText = objXMLDoc.createTextNode("John")
objNewNode.appendChild(objNewText)

Set objCurrNode = objXMLDoc.documentElement
objCurrNode.appendChild(objNewNode)
Set objCurrNode = objCurrNode.lastChild


Set objNewNode = objXMLDoc.createElement("name")
Set objNewText = objXMLDoc.createTextNode("Alex")
objNewNode.appendChild(objNewText)

Set objCurrNode = objXMLDoc.documentElement
objCurrNode.appendChild(objNewNode)
Set objCurrNode = objCurrNode.lastChild

objXMLDoc.Save("names2.xml")

This is the input file.
Names.xml
<names>
   <name>Alice</name>
   <name>Bert</name>
   <name>Charlie</name>
   <name>Diane</name>
   <name>Eric</name>
</names>

This is the output file.
<names>
    <name>Alice</name>
    <name>Bert</name>
    <name>Charlie</name>
    <name>Diane</name>
    <name>Eric</name>
    <name>John</name><name>Alex</name></names>

My question is, how can I write it on separate line for the new added names?.
Thanks.







Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I attach a file to an email in my .vbs file savoym VBScript 3 July 2nd, 2011 08:02 AM
Update xml file simultaneously from two .net app rehna General .NET 1 May 9th, 2008 08:33 AM
Force SQL to update the data from an xml file ivanv SQL Server 2005 0 April 23rd, 2007 04:07 AM
how to update a xml file billbillbill XML 2 April 11th, 2007 08:23 AM
Getting VB.NET to load & update XML file kyma XML 0 March 19th, 2005 04:58 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.