Wouldn't it be more productive if what the question was was actually inserted into the subject area. instead of a generic term. Subscribers could instantly see if it's something they might be interested in instead of opening the email to see what "Simple Questions" actually is.

----- Original Message ----- From: "Stewart Anderson" <[EMAIL PROTECTED]> To: "Richard Lee" <[EMAIL PROTECTED]>; "Perl Beginners" <beginners@perl.org>
Cc: "Stewart Anderson" <[EMAIL PROTECTED]>
Sent: Wednesday, October 22, 2008 3:16 AM
Subject: RE: :Simple question



-----Original Message-----
From: Richard Lee [mailto:[EMAIL PROTECTED]
Sent: 22 October 2008 06:00
To: Perl Beginners
Subject: XML::Simple question

while trying to study the article on perlmonks.org,

http://perlmonks.org/?node_id=490846

regarding XML parsing, I need bit of clarfication.

how do I parse out

<image src="http://www.oreilly.com/catalog/covers/perlbp.s.gif";
             width="145" height="190" />


I tried $book->{image}->{src}... but doesn't work.. I need some
understanding on how these information is stored.



parsing code

  use XML::Simple qw(:strict);

  my $library  = XMLin($filename,
    ForceArray => 1,
    KeyAttr    => {},
  );

  foreach my $book (@{$library->{book}}) {
    print $book->{title}->[0], "\n"

  }

XML file

<library>
    <book>
      <title>Perl Best Practices</title>
      <author>Damian Conway</author>
      <isbn>0596001738</isbn>
      <pages>542</pages>
      <image src="http://www.oreilly.com/catalog/covers/perlbp.s.gif";
             width="145" height="190" />
    </book>
    <book>
      <title>Perl Cookbook, Second Edition</title>
      <author>Tom Christiansen</author>
      <author>Nathan Torkington</author>
      <isbn>0596003137</isbn>
      <pages>964</pages>
      <image src="http://www.oreilly.com/catalog/covers/perlckbk2.s.gi
+f"
             width="145" height="190" />
    </book>
    <book>
      <title>Guitar for Dummies</title>
      <author>Mark Phillips</author>
      <author>John Chappell</author>
      <isbn>076455106X</isbn>
      <pages>392</pages>
      <image src="http://media.wiley.com/product_data/coverImage/6X/07
+645510/076455106X.jpg"
             width="100" height="125" />
    </book>
  </library>



--
I gave up with XML::Simple  it did not seem to  work  (well I could not
getit  to work)  in the way that  the documentation suggested.

I  switched to XML::Smart and it works perfectly.  I use XML Spy to dig
out the XPath etc and work with that.

Stu




Information in this email including any attachments may be privileged, confidential and is intended exclusively for the addressee. The views expressed may not be official policy, but the personal views of the originator. If you have received it in error, please notify the sender by return e-mail and delete it from your system. You should not reproduce, distribute, store, retransmit, use or disclose its contents to anyone. Please note we reserve the right to monitor all e-mail communication through our internal and external networks. SKY and the SKY marks are trade marks of British Sky Broadcasting Group plc and are used under licence. British Sky Broadcasting Limited (Registration No. 2906991), Sky Interactive Limited (Registration No. 3554332), Sky-In-Home Service Limited (Registration No. 2067075) and Sky Subscribers Services Limited (Registration No. 2340150) are direct or indirect subsidiaries of British Sky Broadcasting Group plc (Registration No. 2247735). All of the companies mentioned in this paragraph are incorporated in England and Wales and share the same registered office at Grant Way, Isleworth, Middlesex TW7 5QD.

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to