CA_Tallguy has asked for the wisdom of the Perl Monks concerning the following question:
Oh mighty Perl Monks, please assist me through this terribly frustrating (yet likely very simple to solve) roadblock. I'm trying to access data in a very very large XML file to process and selectively load into database. I am able to print out the data I am after but can't seem to assign to a variable that will persist. I need to collect all the fields for the database row in order to format my insert. Thanks in advance for any wisdom you might share with me.
#!/usr/bin/perl use XML::LibXML::Reader; my $reader = XML::LibXML::Reader->new(location => "parts.xml") or die "cannot read file.xml\n"; while($reader->read) { ## VARIABLE ASSIGNMENT DOES NOT PERSIST $price = $reader->readInnerXml if $reader->localName eq 'price'; ## THESE PRINT EXPECTED VALUES print $reader->readInnerXml if $reader->localName eq 'price'; print $reader->readInnerXml if $reader->localName eq 'url'; print $reader->readInnerXml if $reader->localName eq 'imageurl'; print $reader->readInnerXml if $reader->localName eq 'name'; }
The XML looks like this....
<product> <name>5 Spoke Wheel</name> <description>Reconditioned OEM</description> <price>123.45</price> <url>http://www.foo.com</buyurl> <imageurl>http://www.foo.com/foo.jpg</imageurl>] </product>
|
|---|