I'm new to XML parsing. Seems like a great tool.
Here's the XML I'm attempting to parse:
<?xml version="1.0" encoding="UTF-8" ?>
- <message_data>
- <message id="1015020">
<message_subject>this is a test</message_subject>
<date_sent>2007-10-16 11:01:31</date_sent>
<message_notes>E-mail Created automatically 10/16/2007 13:25:27</message_notes>
<bill_codes />
<sent_total>3</sent_total>
<sent_total_html>3</sent_total_html>
<sent_total_plain>0</sent_total_plain>
<sent_rate_total>100.00</sent_rate_total>
<sent_rate_html>100.00</sent_rate_html>
<sent_rate_plain>0.00</sent_rate_plain>
<delivered_total>3</delivered_total>
<delivered_html>3</delivered_html>
<delivered_plain>0</delivered_plain>
<delivered_rate_total>100.00</delivered_rate_total>
<delivered_rate_html>100.00</delivered_rate_html>
<delivered_rate_plain>0.00</delivered_rate_plain>
<bounced_total>0</bounced_total>
<bounced_html>0</bounced_html>
<bounced_plain>0</bounced_plain>
<bounced_rate_total>0.00</bounced_rate_total>
<bounced_rate_html>0.00</bounced_rate_html>
<bounced_rate_plain>0.00</bounced_rate_plain>
<invalid_total>0</invalid_total>
<invalid_rate_total>0.00</invalid_rate_total>
<optout_total>0</optout_total>
<optout_rate_total>0.00</optout_rate_total>
<withheld_total>0</withheld_total>
<globally_suppressed />
<suppressed_total />
<clicked_total>0</clicked_total>
<clicked_unique>0</clicked_unique>
<clicked_rate_unique>0.00</clicked_rate_unique>
<clicked_rate_aps>0.00</clicked_rate_aps>
<opened_total>4</opened_total>
<opened_unique>2</opened_unique>
<opened_rate_unique>66.67</opened_rate_unique>
<opened_rate_aps>2.00</opened_rate_aps>
<campaign_name />
<campaign_id>0</campaign_id>
<campaign_type />
<has_dynamic_content>0</has_dynamic_content>
<has_delivery_report>0</has_delivery_report>
<link_append_statement />
<timezone />
<ftf_forwarded>0</ftf_forwarded>
<ftf_signups>0</ftf_signups>
<ftf_conversion_rate>0.00</ftf_conversion_rate>
- <included_groups>
<segment id="516636">Bryant Public Test</segment>
</included_groups>
<included_smartlists />
<excluded_groups />
<excluded_smartlists />
</message>
</message_data>
I can get values under "MESSAGE", but am using the messageID (message id="1015020") as the key to the data I'm looking to import into MySQL -- and I keep getting an empty value when I try to define it.
Any suggestions how to capture the parent ID?
Here's my code:
<?php
require("MagicParser.php");
function myRecordHandler($message)
{
$mid = $message["ID"];
$subject = $message["MESSAGE_SUBJECT"];
$notes = $message["MESSAGE_NOTES"];
$date = $message["DATE_SENT"];
$sent = $message["SENT_TOTAL"];
$bounced = $message["BOUNCED_TOTAL"];
$opened = $message["OPENED_UNIQUE"];
echo $mid."<br>".$subject."<br>".$date."<br>".$notes."<br>".$sent."<br>".$bounced."<br>".$opened."<br><br>";
}
$url = "http://myurl";
MagicParser_parse("$url","myRecordHandler","xml|MESSAGE_DATA/MESSAGE/");
?>
Thanks in advance for any help you an offer.
That dawned on me last night, David. Thanks for your prompt reply.
Hi,
The ID attribute of the MESSAGE element will be in the $record array as "MESSAGE-ID", not just "ID" as you have used in your example code. In other words, instead of:
$mid = $message["ID"];
use:
$mid = $message["MESSAGE-ID"];
That should do the trick!
Cheers,
David.