Windows Scripting
  Home arrow Windows Scripting arrow Page 2 - Modifying XML Files in WSH
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
WINDOWS SCRIPTING

Modifying XML Files in WSH
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 4
    2008-12-08

    Table of Contents:
  • Modifying XML Files in WSH
  • Adding new elements
  • Placing new elements
  • Modifying and deleting existing records

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Modifying XML Files in WSH - Adding new elements


    (Page 2 of 4 )

    In order to add a new element, we must first create a reference to the new element's parent object. This is most easily done by using a query string. In this case, we need to add a new track element. If you examine the XML file, you will see that track elements are children of the trackList element.

    Set objTrackList = objXmlDoc.selectSingleNode("/playlist/trackList")

    The selectSingleNode method is used to return a single node based upon the query string provided. In this case, it returns a reference to the trackList element.

    Set objTrack = objXmlDoc.createElement("track")

    objTrackList.appendChild objTrack

    Next, you can use the XML Document object's createElement method to create a new track element. It is then attached to the document as a child of the trackList node by using the appendChild method exposed by that object.

    Set objLocation = objXmlDoc.createElement("location")

    objLocation.Text = "http://www.nilpo.com/pub/tracks/Crossfade%20-%20Cold.mp3"

    objTrack.appendChild objLocation

     

    Set objTitle = objXmlDoc.createElement("title")

    objTitle.Text = "Dead Skin"

    objTrack.appendChild objTitle

     

    Set objCreator = objXmlDoc.createElement("creator")

    objCreator.Text = "Crossfade"

    objTrack.appendChild objCreator

     

    Set objInfo = objXmlDoc.createElement("info")

    objInfo.Text = "http://phobos.apple.com/WebObjects/MZStore.woa/wa/" _

       & "viewAlbum?i=187470715%38id=187470617%38s=143441"

    objTrack.appendChild objInfo

     

    Set objAlbum = objXmlDoc.createElement("album")

    objAlbum.Text = "Crossfade"

    objTrack.appendChild objAlbum

     

    Set objTrackNum = objXmlDoc.createElement("trackNum")

    objTrackNum.Text = "2"

    objTrack.appendChild objTrackNum

    Each of the property elements can then be added to the newly created track element in the same manner.  The text property of each newly created child element is set using the text property.

    objXmlDoc.save "C:Playlist.xml"

    Once you've added all of the required elements, a call to the XML Document object's save method will write those changes to the XML file.

    More Windows Scripting Articles
    More By Nilpo


     

    WINDOWS SCRIPTING ARTICLES

    - More Windows Scripting Workarounds from Nilpo
    - Overloading Methods and More in VBScript
    - Improving MFC for Windows Vista
    - Regular Expressions in VBScript
    - Working with Dates in WMI
    - Completing Calendars with VBScript Date Func...
    - Building Calendars with VBScript Date Functi...
    - Working With Dates and Times in VBScript
    - Designing WCF DataContract Classes Using the...
    - Understanding Dates and Times in VBScript
    - Working With Arrays in VBScript
    - Compressed Folders in WSH
    - Using .NET Interops in VBScript
    - Nilpo`s Scripting Secrets, Vol I
    - Database operations using Silverlight 2.0 WC...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    Stay green...Green IT