Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

script to extract text from XML file

Status
Not open for further replies.

biglebowski

Technical User
Jan 29, 2004
3,117
GB
I have an xml file which contains all the messages for a system monitor application. I've been asked to come with a way of automating a task to find out what files were deleted each day when a job runs. The status is held below in the xml file:

<Message id="8523" instanceId="2011/04/06-18:06:18.700_172.18.225.241_8523_Audio Watermark_E:\OspData\29-Dec-2010" status="Existing" severity="Informational" firstReceiveTime="2011-04-06T18:06:18.7005001+01:00">
<Text>Audio Watermark disk manager last deleted folder E:\OspData\29-Dec-2010</Text>
<Params>
<Param type="String">Audio Watermark</Param>
<Param type="String">E:\OspData\29-Dec-2010</Param>
</Params>

What I'd like to do is have a script that will search for a value and then send the text in the next matching value to a text file.

I want to use the value Message id="8523" as the search field and then send the data in the <Param type="String">E:\OspData\29-Dec-2010</Param> to a text file.

I have the following from searching other sites but it creates an error and I don't know how to extract the second param type string info:

set xmlDoc=CreateObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("C:\LastSystemStatus.xml")
Application = xmlDoc.GetElementsByTagName("Message id="8523"").item(0).text
wscript.echo application


Biglebowskis Razor - with all things being equal if you still can't find the answer have a shave and go down the pub.
 
(!! Major shot in the dark !!)

add delimiter quotes

Code:
Application = xmlDoc.GetElementsByTagName("Message id=[red]""[/red]8523[red]""[/red]").item(0).text

but isn't the tag name "Message". the id is a property. so..

Code:
xmlMessages = xmlDoc.GetElementsByTagName("Message")
for i = 0 to xmlMessages.length
   application = xmlMessages.getElementsById("8523")[i].text.data
   'do stuff
next

-Geates

"Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live."
- Martin Golding

"There are seldom good technological solutions to behavioral problems."
- Ed Crowley, Exchange guru and technology curmudgeon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top