Any interest in Perl and XML
taa0 at cris.com
taa0 at cris.com
Sat May 20 00:23:03 CDT 2000
Bob La Quey wrote:
>
>
> How about showing us some exmple code. I did this stuff about a year ago
> as a learning exercise. I don't recall if XML::Simple was available then.
> Is is a SAX interface?
Not a SAX interface. Here's an example:
-------------- next part --------------
#!/usr/local/bin/perl -w
use XML::Simple;
my $in;
while(<DATA>) { $in .= $_; }
my $config = XMLin($in);
my $category = ${$config}{'category'};
print "category is $category\n";
my $fruithash = ${$config}{'fruit'};
foreach my $key (keys %$fruithash) {
print "\t$key:\n";
my $pair = ${$fruithash}{$key};
foreach my $attrib (keys %$pair) {
print "\t\t$attrib is ${$pair}{$attrib}\n";
}
}
__END__
<!--
this is just a comment
-->
<!DOCTYPE fruits [
<!ELEMENT fruits (category,fruit*)>
<!ELEMENT category (#PCDATA)>
<!ELEMENT fruit (name,color)>
<!ELEMENT name (#PCDATA)>
<!ELEMENT color (#PCDATA)>
]>
<fruits>
<category>citrus</category>
<fruit>
<name>orange</name>
<color>orange</color>
</fruit>
<fruit>
<name>lemon</name>
<color>yellow</color>
</fruit>
<fruit>
<name>lime</name>
<color>green</color>
</fruit>
</fruits>
More information about the San-Diego-pm
mailing list