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

Reading XML Files in WSH
By: Nilpo
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 5 stars5 stars5 stars5 stars5 stars / 2
    2008-12-01

    Table of Contents:
  • Reading XML Files in WSH
  • Getting started
  • More advanced queries
  • Further filtering results
  • Constructing advanced queries
  • What to do when it doesn’t work

  • 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


    Reading XML Files in WSH - Further filtering results


    (Page 4 of 6 )

    Let’s not stop there. To truly harness the power of a database, you need to be able to perform conditional queries. In WMI you would associate these with Where clauses. Where clauses serve to further filter your results based upon field values—or in this case, element text values.

    Set colTracks = objXmlDoc.selectNodes( _

       "/playlist/trackList/track [creator = 'Breaking Benjamin']")

     

    For Each objTrack In colTracks

       Set colProperties = objTrack.childNodes

      

       For Each objProperty In colProperties

           WScript.Echo objProperty.baseName & ":", objProperty.Text

       Next

      

       WScript.Echo ""

    Next

    This code sample will return all track instances where the creator value is equal to “Breaking Benjamin.” In other words, it only returns tracks recorded by Breaking Benjamin.

    The important thing to see here is the use of brackets to denote the “where” clause. The query lists all elements that match the path provided (which represent individual track entries) and then further filters them based on the value of the track’s creator element—returning only those whose value is equal to the value provided.

    But it doesn’t stop there. You can use any of the standard comparison operators including =, <, >, <=, and >=.  You can negate any of them by prefacing them with an exclamation point.  For example, to specify "not equal" you would use !=.

    Set colTracks = objXmlDoc.selectNodes( _

       "/playlist/trackList/track [creator != 'Breaking Benjamin']")

    So this example would then return all track entries except those recorded by Breaking Benjamin. Pretty cool, huh? Okay, so you’re still not that impressed.  Fine, let’s make it a little more complicated. Let’s filter our results based on more than one field.

    Set colTracks = objXmlDoc.selectNodes( _

       "/playlist/trackList/track " _

          & "[creator = 'Breaking Benjamin' and title != 'So Cold']")

    You can specify more than one element to filter by combining them into more complex query statements inside of the brackets. In this case, I’ve used the “and” operator to return all tracks where the creator element contains “Breaking Benjamin” and the title element does not contain “So Cold.” You can also create converse statements by using the “or” operator.

    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 3 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek