Brian Bwarn
2006-07-24 21:59:59 UTC
I'm just starting out with XML::Simple and can't get
any output to display to STDOUT. What am I missing?
-------------------
Source XML snippet:
-------------------
<dataschemas>
<dataschema name="defaultDB">
<includes>
<include name="Base Metadata"/>
<include name="Extracted Re-Map"/>
</includes>
<attributes>
<attribute category="" parser="TextParser"
extract="true" segmentation="soft"/>
</attributes>
</dataschema>
</dataschemas>
---------------
Perl code:
----------------
# use modules
use XML::Simple;
use Data::Dumper;
# create object
$xml = new XML::Simple (KeyAttr=>[]);
# read XML file
$data=
$xml->XMLin("C:\datafiles\specialIncludes.xml");
# dereference hash reference
# access <dataschemas> array
print "before loop ...\n";
foreach $d (@{$data->{dataschema}}) {
print "in \$d loop ...\n";
print "dataschema is: ", $d->{includes}->{name},
"\n";
}
print "finished\n";
---------------
Output:
---------------
before loop ...
finished
Thanks, BW
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
any output to display to STDOUT. What am I missing?
-------------------
Source XML snippet:
-------------------
<dataschemas>
<dataschema name="defaultDB">
<includes>
<include name="Base Metadata"/>
<include name="Extracted Re-Map"/>
</includes>
<attributes>
<attribute category="" parser="TextParser"
extract="true" segmentation="soft"/>
</attributes>
</dataschema>
</dataschemas>
---------------
Perl code:
----------------
# use modules
use XML::Simple;
use Data::Dumper;
# create object
$xml = new XML::Simple (KeyAttr=>[]);
# read XML file
$data=
$xml->XMLin("C:\datafiles\specialIncludes.xml");
# dereference hash reference
# access <dataschemas> array
print "before loop ...\n";
foreach $d (@{$data->{dataschema}}) {
print "in \$d loop ...\n";
print "dataschema is: ", $d->{includes}->{name},
"\n";
}
print "finished\n";
---------------
Output:
---------------
before loop ...
finished
Thanks, BW
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com