- Consider the original XML data:
<Order>
<Number>01234</Number>
<Status>OPEN</Status>
</Order> - The XML data is translated into Perl data structure, utilizing XML::SAX(why?):
The unordered hash index will not mangle the report anymore since:$VAR1 = {
'Order' => {
'Status' => 'OPEN',
'Number' => '01234'
}
}; - Along the way (of parsing XML data using XML::SAX), a report template is created with references at the right places.
Status Notes <Order> <Number>01234</Number> ${$REPORT[0]}{'RESULT'} ${$REPORT[0]}{'NOTES'} <Status>OPEN</Status> ${$REPORT[1]}{'RESULT'} ${$REPORT[1]}{'NOTES'} </Order> - To the bridge the result of comparison and the report template, another data structure is created (will be called: bridge) and it has an exact hash structure as the XML data, but it is holding references to the report template.
$BRIDGE1 = {
'Order' => {
'Status' => '$REPORT[1]',
'Number' => '$REPORT[0]'
}
}; - Consider the check data for the XML data above:
Readability is the main reason the check/validation is written in XML format.<Order>
<Number><SQL>'SELECT Status FROM Order WHERE ORDER_ID = <value>'</SQL></Number>
<Status><SQL>'SELECT OrdNum FROM Order WHERE ORDER_ID = <value>'</SQL></Status>
</Order> - Converted to Perl data structure using XML::Simple
$CHECK1 = {
'Order' => {
'Status' => { SQL => 'SELECT Status FROM Order WHERE ORDER_ID = <value>'},
'Number' => { SQL => 'SELECT OrdNum FROM Order WHERE ORDER_ID = <value>'},
}
}; - Iterating through the XML hash structure, while maintaining same path of traversal with the bridge and check hash structure:
$XML{'Order'}
-> $BRIDGE1{'Order'}
-> $CHECK1{'Order'}
$XML{'Order'}{'Status'}
-> $BRIDGE1{'Order'}{'Status'}
-> $CHECK1{'Order'}{'Status'} - Find the end of XML hash structure branch to extract the value.
if (ref($XML{'Order'}{'Status'}) eq "") {
$XMLValue = $XML{'Order'}{'Status'};
} - Get the SQL syntax from check hash and get the content from database.
if (exists $CHECK1{'Order'}{'Status'}{'SQL'}) {
$SQL = $CHECK1{'Order'}{'Status'}{'SQL'};
}
else {
# bitch later: no SQL defined.
}
$DBVALUE = getValue($SQL); - Compare the content from XML hash structure and database and write the result out to $REPORT[$index], which provided by bridge hash.
if ($XMLValue eq $DBVALUE) {
eval "\${".$BRIDGE1{'Order'}{'Status'}."}{'RESULT'} = 'PASSED';";
eval "\${".$BRIDGE1{'Order'}{'Status'}."}{'NOTES'} = '$NOTE';";
}
else {
eval "\${".$BRIDGE1{'Order'}{'Status'}."}{'RESULT'} = 'FAILED';";
eval "\${".$BRIDGE1{'Order'}{'Status'}."}{'NOTES'} = '$NOTE';";
} - After traversing all of the branches of XML hash structure, open the report template and evaluate template, producing:
Status Notes <Order> <Number>01234</Number> PASSED <Status>OPEN</Status> PASSED </Order>
Tuesday, January 22, 2008
How To Slow Cook A Piglet
This is how the pieces are glued together:
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment