Wednesday, January 23, 2008

Why Convert XML Data To Hash Structure Using XML::SAX?

Instead of using XML::Simple? The structure, generated by XML::Simple, is not consistent since it recognizes an empty tag as empty hash structure, instead of null string.
  1. Consider this XML data:
    <Order>
    <Number>01234</Number>
    <Status />
    </Order>
  2. Using XML::Simple produces:
    $VAR1 = {
    'Order' => {
    'Status' => {},
    'Number' => '01234'
    }
    };
  3. Utilizing XML::SAX, we could insert a null string instead of an empty hash structure:
    $VAR1 = {
    'Order' => {
    'Status' => '',
    'Number' => '01234'
    }
    };
Remember: it is simpler to assume that all end of hash structure branch is represented by ref($hash) eq "".

No comments: