Tuesday, January 15, 2008

Comparing Data Between XML And Database

There is a need to instantly verify the content in XML with the content that's being pushed the application to the database.

The project started this Tuesday.

I started with converting the structure of the XML data into Perl hash using XML::Simple. Also, the data structure could serve as the validation data.

Consider this XML data:
<Order>
<Number>01234</Number>
<Status>OPEN</Status>
</Order>

Converting the XML to Perl hash using XML::Simple (with KeepRoot => 1) yields:
$VAR1 = {
'Order' => {
'Status' => 'OPEN',
'Number' => '01234'
}
};
The hash structure could be manipulated as validation data:
$VAR1 = {
'Order' => {
'Status' => 'SELECT Status FROM Order WHERE ORDER_ID = <value>',
'Number' => 'SELECT OrdNum FROM Order WHERE ORDER_ID = <value>'
}
};
Iterating through the data structure to extract the data and the SQL statement to extract content from database, it is feasible to validate the entire XML structure provided a validation data with similar structure using an algorithm.

No comments: