NAME
wtr2_dom
SYNOPSYS
perl wtr2_dom
DESCRIPTION
This code uses the XML::DOM manpage to process the invoices
I have never liked the DOM. The Object Model is good, very complete and solid, but the API is very Java oriented (camels are good as Perl mascottes, not as veryLongMethodNames), and at least at level 1 (XML::DOM is a level 1 DOM implementation) quite weak and indeed dangerous.
Having gotten this out of my system...
Writing the DOM example wasn't particulary hard. It was long and quite painful, but more boring than difficult.
A minor annoyance, that could actually be a blessing in a different context:
every time I needed to access an attribute for an optional element
(DeliveredQuantity for example) I had to check the existence of the element,
or calling getAttribute
on undef
(the non existent element) would cause
the script to die
. the XML::Simple manpage and the likes, by contrast, would let
me access non existent hash values in the Perl data structure without
complaining. Having to check is a pain in a short script like this one, but
could be very useful in a bigger project, as it is always better to have the
code die with a bang than fail silently (and cause errors later).
I wrote a little layer on top of it, with the first_child, children and text functions, that basically ensure that when I get a child I get the proper one, and not an extra whitespace, comment or other, that would happen to be in the XML.
AUTHOR
Michel Rodriguez <mirod@xmltwig.com>
LICENSE
This code is Copyright (c) 2003 Michel Rodriguez. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Comments can be sent to mirod@xmltwig.com
SEE ALSO
XML::DOM
Ways to Rome 2 - Kourallinen Dollareita : http://www.xmltwig.com/article/ways_to_rome_2/