Hi, My objective is to read a xml file and extract data off of it as both the elements and attributes...well here, let me start by some codes.
<site-catalog> <site> <name>abc</name> <header> <date id = "1992-06-17T00:00:00"> <fullname>AybBemGim</fullname> <a>101 </b> <b>UNKN</b> ... <operator>Zarzand</operator> <agency>NONE</agency> <run-by>Pepo</run-by> <observables>UNKN</observables> </date> <date id = "1992-06-26T00:00:00"> <fullname>AybBemGim</fullname> <b>101</b> <l>+342809.83</l> .... </date> </header> </site> </site-catalog>
I want to load these to a hash array so I can sort by the date id and extract the data inside that date id. my perl is as such:
#!/usr/bin/perl use XML::Simple; use Data::Dumper; $xmlfile = "/home/rob/xml/config.xml"; #create object $xml = new XML::Simple; #read XML file $hash = $xml->XMLin($xmlfile); %element = $hash->{site}->{header}->{date}; foreach $key (sort keys %element) { print $key; } #print Dumper $hash;
How can I read the date id and the elements inside this tree?
(I have a feeling the answer is staring right in front of me but I haven't figured it out yet)
Can you guys give me some hints/ideas?
..thanx..

In reply to XML::Parser help by rhxk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.