Windows Scripting
  Home arrow Windows Scripting arrow 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


    (Page 1 of 4 )

    In my last two articles, I showed you how to create and read XML files in WSH. Today, I’m going to bring this series to a close by showing you how to modify XML files. This includes modifying the text data in the file as well as modifying the XML structure.

    To begin, you'll need an XML file to work with. If you don't have the example file from the last two articles, you can grab it here.

    Perhaps the most common reason for modifying an XML file is to append data. This is comparable to adding a new record to a database. Let's take our example XSPF playlist and add another set of track information as follows:

    location: http://www.nilpo.com/pub/tracks/Crossfade%20-%20Cold.mp3

    title: Dead Skin

    creator: Crossfade

    info: http://phobos.apple.com/WebObjects/MZStore.woa/wa/viewAlbum?i=187470715%38id=187470617%38s=143441

    album: Crossfade

    trackNum: 2

    The script first needs to open the XML file and load its document tree.

    Set objXmlDoc = CreateObject("Microsoft.XMLDOM")

    objXmlDoc.async = False

    objXmlDoc.load("C:Playlist.xml")

    This portion of the script returns an XML Document object by creating an instance of Microsoft's XML Parser. Next, the async property is set to false to help ensure that the script does not continue to execute until the file is fully loaded. Finally, the load method is used to load the XML document into the parser.

    Set objRoot = objXmlDoc.documentElement

    The XML Document object exposes a documentElement method which has the net effect of returning the first, or root, element of the document. By creating a reference to the root element, you can traverse the entire document tree from the top down. We don't have a need for this in today's example, but it's important to keep this in mind.

    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-2010 by Developer Shed. All rights reserved. DS Cluster 2 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek