Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: vbscript and xml

From: Martin Honnen <mahotrash@-----.-->
To: NULL
Date: 2/1/2008 1:42:00 PM

Argus Rogue wrote:

> 1.  read each xml file from a directory
> 2. search each xml file (status) for the text fail
> 3.  write to output file in HTML format the status and the file name to
> where you have the following:
>     Status    Name
> -------------------
>     Fail        name of the file

> I found some code to read each file in the directory (part 1) but how do i
> do 2 and 3.

3. is off topic here in comp.text.xml but generally with VBScript or 
JScript you have the Scripting.FileSystemObject to read and write text 
files (and a HTML file is a text file).
So check <URL:http://msdn2.microsoft.com/en-us/library/6kxy1a51(VS.85).aspx>

As for 2., you can use MSXML with script to parse XML documents into a 
document object model, then using MSXML 3 and later you have XPath 
support to find nodes. It is currently not clear to me whether you want 
to find an element named 'fail' or the text 'fail' in some element or 
attribute content.
Your example XML document has an element named 'status' with the 
contents 'fail' so assuming you want to look for such elements you could 
do e.g.
   Set xmlDoc = CreateObject("Msxml2.DOMDocument.3.0")
   xmlDoc.async = False
   If xmlDoc.load("file.xml") Then
      xmlDoc.setProperty "SelectionLanguage", "XPath"
      Set status = xmlDoc.selectSingleNode("//status[. = 'fail']")
      If Not status Is Nothing Then
         ' element was found, write that to file
      Else
         ' element was not found
      End If
   Else
      ' XML document could not be parsed
      ' examine xmlDoc.parseError here
   End If

If you want to look for any element with the contents 'fail' then use
   xmlDoc.selectSingleNode("//*[. = 'fail']")
if you want to look for elements containing the string 'fail' then use
   xmlDoc.selectSingleNode("//*[contains(., 'fail')]")

-- 

	Martin Honnen
	http://JavaScript.FAQTs.com/


transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent