jmurphy has asked for the wisdom of the Perl Monks concerning the following question:


Warning: I'm a Perl/XML newbie. I have an interesting (at least I think so) XML problem that I was hoping to solve with Perl and its XML extensions. I've been hanging out on the site (surfing some previous postings regarding the specific modules that I've been playing with) and I'm just about through the Perl & XML O'Reilly book (really enjoyed the read). Enough chit chat.

I'm using Matt Sergeant's XML::Generator::DBI module to query my data source and return an XML document similar to the following:

<?xml version="1.0" encoding="UTF-8"?> . . . <Message> <MessageID>376</MessageID> <CreateDate>2002-05-31 09:14:41.047</CreateDate> <Subject>Re: Msg54</Subject> </Message> <Message> <MessageID>377</MessageID> <CreateDate>2002-06-04 08:47:47.627</CreateDate> <Subject>Re: Msg95</Subject> </Message> <Message> <MessageID>378</MessageID> <CreateDate>2002-06-04 08:51:58.390</CreateDate> <Subject>Demo</Subject> </Message> <Message> <MessageID>379</MessageID> <CreateDate>2002-06-04 08:54:38.593</CreateDate> <Subject>Re: Demo</Subject> </Message> . . .
The problem is that I have to extract (inclusively) the data between each <Message>...</Message> section and write each chunk to its own file using the value in <MessageID>...</MessageID> for the file name. I understand that this module generates SAX events as a result of the query however, I was considering building a DOM tree and using XPath to extract the necessary text. Can anyone offer any advice on my purposed method of attack? I understand the benefits of using SAX with regards to performance however, the ease of the XPath syntax seems very appealing.

Thanks so much,