Windows Scripting
  Home arrow Windows Scripting arrow Page 5 - 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 - Constructing advanced queries


    (Page 5 of 6 )

    I bet right about now you’re wondering whether or not you can combine all of these techniques to create even more complex queries. In short, the answer is: yes. What fun would it be if you couldn’t do that?!

    Set colTitles = objXmlDoc.selectNodes( _

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

     

    For Each objTitle In colTitles

       WScript.Echo objTitle.Text

    Next

    This query combines the two techniques we’ve seen already by first filtering results based upon the creator element, and then only returning the specified title element.

    Wait, I know your next question. And yes, you are exactly right. You can specify more than one specific field even when using a complex query like this.

    Set colProperties = objXmlDoc.selectNodes( _

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

           & "/(title | album)")

     

    For Each objProperty In colProperties

       WScript.Echo objProperty.Text

    Next

    This query first returns all elements that match the path <playlist><trackList><track>. Then it filters those results and returns only those whose creator is “Breaking Benjamin.” Finally, it returns only the title and album elements for those tracks.

    Take a breath. It looks a whole lot harder than it really is. Look at the query one piece at a time and think about how it filters the results. Each piece builds upon the results from the piece before. It’s a pretty logical process. You’ll get a handle on it in no time.

    It’s okay if you need to read through this section again. These queries are a little unusual to look at when you first begin. The best, and easiest, way to learn them is to grab an XML file and just start playing. I promise, if you try them out and watch the results, you’ll pick this up in no time at all.

    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 1 Hosted by Hostway
    Stay green...Green IT