For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > March 2006 > Really simple XML question









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Really simple XML question
Dave Adams

2006-03-31, 6:57 pm

How do I print the value of 'Time Magazine'?

Here is my file (ejournlist.xml):

<?xml version='1.0'?>
<EJOURNLIST>
<EJOURN>
<TI>Africa Confidential</TI>
<ISSUE>Vol. 1, no.1</ISSUE>
<FILEFORMAT>PDFformat</FILEFORMAT>
</EJOURN>
<EJOURN>
<TI>Time Magazine</TI>
<ISSUE>Vol. 1, no.1</ISSUE>
<FILEFORMAT>TXTformat</FILEFORMAT>
</EJOURN>
</EJOURNLIST>

Here is my script:

#!/usr/bin/perl -w
use XML::Simple;
use Data::Dumper;

#create object
my $xml = new XML::Simple;

#read XML file
my $data = $xml->XMLin("ejournlist.xml");

#print output
print Dumper($data);

Mr. Shawn H. Corey

2006-03-31, 6:57 pm

On Fri, 2006-31-03 at 09:39 -0500, Dave Adams wrote:
> How do I print the value of 'Time Magazine'?


What do you mean by 'value'? I see no element <value > or even <VALUE >
and no attribute with those names.

>
> Here is my file (ejournlist.xml):
>
> <?xml version='1.0'?>
> <EJOURNLIST>
> <EJOURN>
> <TI>Africa Confidential</TI>
> <ISSUE>Vol. 1, no.1</ISSUE>
> <FILEFORMAT>PDFformat</FILEFORMAT>
> </EJOURN>
> <EJOURN>
> <TI>Time Magazine</TI>
> <ISSUE>Vol. 1, no.1</ISSUE>
> <FILEFORMAT>TXTformat</FILEFORMAT>
> </EJOURN>
> </EJOURNLIST>



--
__END__

Just my 0.00000002 million dollars worth,
--- Shawn

"For the things we have to learn before we can do them,
we learn by doing them."
Aristotle

* Perl tutorials at http://perlmonks.org/?node=Tutorials
* A searchable perldoc is at http://perldoc.perl.org/



Dermot Paikkos

2006-03-31, 6:57 pm

On 31 Mar 2006 at 9:39, Dave Adams wrote:

> How do I print the value of 'Time Magazine'?
>
> Here is my file (ejournlist.xml):
>
> <?xml version='1.0'?>
> <EJOURNLIST>
> <EJOURN>
> <TI>Africa Confidential</TI>
> <ISSUE>Vol. 1, no.1</ISSUE>
> <FILEFORMAT>PDFformat</FILEFORMAT>
> </EJOURN>
> <EJOURN>
> <TI>Time Magazine</TI>
> <ISSUE>Vol. 1, no.1</ISSUE>
> <FILEFORMAT>TXTformat</FILEFORMAT>
> </EJOURN>
> </EJOURNLIST>
>
> Here is my script:
>
> #!/usr/bin/perl -w
> use XML::Simple;
> use Data::Dumper;
>
> #create object
> my $xml = new XML::Simple;
>
> #read XML file
> my $data = $xml->XMLin("ejournlist.xml");
>
> #print output
> print Dumper($data);
>


my $i = $data->{EJOURN}->[1]->{TI};
^ ^ ^
hasref array Idx Tagname

print "Val=$i\n";

Don't know what they call the other one :(
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com