khalistoo has asked for the wisdom of the Perl Monks concerning the following question:
Parsing.pl sub parse{ my $parser = XML::LibXML->new(); my $tree = $parser->parse_file($file); open (my $FhResultat, '>', $FichierResultat ); my $root = $tree->getDocumentElement; my @productname = $root->getElementsByTagName('product'); foreach my $child (@productname){ print {$FhResultat} $child->getElementsByTagName('name')->[0]->getFirstChild->getD +ata, "\t", $child->getAttribute('category_id'),"\t", $child->getAttribute('id'), "\t", $child->getElementsByTagName('desc_short')->[0]->getFirstChild +->getData, "\n"; }
Since a normal product will have information in <imageURL_med></imageURL_med> i would like to know how i can code my script to fetch data inside this tag, and return null if there is no data and having the script not stopping when it encounters an empty tag. Thanks a lot in advanceproducts.xml <product category_id="13296" id="675936193" catalog="false" row="1"> <name>Children's Hand Rake</name> <imageURL_med></imageURL_med> <desc_short>Mini gardeners can dig, rake and scoop out the +ir own plot with this children's hand rake, complete with contoured h +andles and durable metal heads.</desc_short> </product>
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: XML::LibXML- Escape Empty Tags
by Your Mother (Archbishop) on Jul 30, 2009 at 16:36 UTC | |
by khalistoo (Initiate) on Jul 31, 2009 at 08:46 UTC | |
by Your Mother (Archbishop) on Jul 31, 2009 at 17:31 UTC | |
by Anonymous Monk on Jul 31, 2009 at 09:18 UTC | |
Re: XML::LibXML- Escape Empty Tags
by ramrod (Priest) on Jul 30, 2009 at 14:35 UTC | |
by ikegami (Patriarch) on Jul 30, 2009 at 16:21 UTC | |
by Anonymous Monk on Jul 30, 2009 at 15:21 UTC | |
by ramrod (Priest) on Jul 30, 2009 at 15:58 UTC | |
by khalistoo (Initiate) on Jul 31, 2009 at 08:36 UTC | |
Re: XML::LibXML- Escape Empty Tags
by Anonymous Monk on Jul 31, 2009 at 14:42 UTC |