Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - vbscript and xml >Thread Next - Re: vbscript and xml Re: vbscript and xmlTo: 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/ | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
