Altova Mailing List Archives>Archive Index >comp.text.xml Archive Home >Recent entries >Thread Prev - Re: vbscript and xml >Thread Next - Re: vbscript and xml Re: vbscript and xmlTo: NULL Date: 2/1/2008 3:44:00 PM Hey Martin, Thanks for the reply, it is greatly appreciated. Just one question though, in your code, you read in only my file, how can i read an entire directory and then produce the results of: Fail file.xml Fail file2.xml Fail file12.xml and etc... "Martin Honnen" <mahotrash@y...> wrote in message news:47a3139c$0$9105$9b4e6d93@n...... > 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 | |||
|
