views:

57

answers:

2

The problem is there is a folder ./log/ containing the files like:

jan2010.xml, feb2010.xml, mar2010.xml, jan2009.xml, feb2009.xml, mar2009.xml ...

each xml file would like:

<root><record name="bob" spend="20"></record>...(more records)</root>

I want to write a piece of ColdFusion code (log.cfm) that simply parsing those xml files. For the front end I would let user to choose a year, then the click submit button. All the content in that year will be show up in separate table by month. Each table shows the total money spent for each person. like:

person   cost
bob      200
mike     300
Total    500

Thanks.

+2  A: 

The short answer is that, if your XML is correctly formatted, you can use the XMLParse() function to get the XML into a CF data object.

Sergii pointed out that XMLParse cna take a path, so you can simply read the file directly into it and assign the results to a variable.

The data should look something like an array of structures. Use CFDUMP on your CF data object to view it and help you figure it out.

Ben Doom
XMLParse() can take the path as argument, so using CFFILE is not required.
Sergii
A: 

I would strongly urge you to check out Microsoft's "Log Parser" if you're on Windows. It provides essentially a SQL-like query interface to all manner of log files. There's an app called "Log Parser Lizard" which provides a GUI for testing out "queries", and then you can cfexecute logparser with the queries you come up with.

Not sure if there's an equivalent for linux.

If you're on Windows and interested in hearing more, let me know. I had it hooked into an ANT task that downloaded log files every night, parsed them, generated reports, etc. It worked very well.

marc esher