dstefani has asked for the wisdom of the Perl Monks concerning the following question:
<AvailableBatch> <Date>08/31/2004</Date> <Available> <Sku>40</Sku> <Part>10 </Part> <Location>20</Location> <Qty>1</Qty> <Time>18:38:01</Time> </Available> <Available> <Sku>40</Sku> <Part>10 </Part> <Location>60</Location> <Qty>0</Qty> <Time>18:38:01</Time> </Available> </AvailableBatch>
I need to treat each <Available> grouping as a record and get the <Part> and <Qty> for each, then test each record against a MySQL table.
Below is attempt to try and use XML::Path, some code I gleaned from Perl / XML.
I can see how to get one element, but I could use a hint at how to group the child elements. The samples I see all count of the elements having attributes, which my file does not use.
Thanks, I hope I'm not too far to the "help me write me script" side, I just need a good hint or two.
-dstefaniuse XML::XPath; my $file = 'available_batchnyyn.xml'; my $xp = XML::XPath->new(filename=>$file); my $nodeset = $xp->find('//Sku'); my @zipcodes; # Where we'll put our results if (my @nodelist = $nodeset->get_nodelist) { @zipcodes = map($_->string_value, @nodelist); @zipcodes = sort(@zipcodes); local $" = "\n"; print "I found these zipcodes:\n@zipcodes\n"; } else { print "The file $file didn't have any 'zip' elements in it!\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: XML::XPath tricks and tips
by mirod (Canon) on Sep 02, 2004 at 00:18 UTC | |
|
Re: XML::XPath tricks and tips
by Aristotle (Chancellor) on Sep 02, 2004 at 00:16 UTC | |
|
Re: XML::XPath tricks and tips
by johnnywang (Priest) on Sep 02, 2004 at 00:26 UTC | |
|
Re: XML::XPath tricks and tips
by gmpassos (Priest) on Sep 02, 2004 at 16:03 UTC |