Hello monks, I am new to Perl and I am trying the past couple of days to use the Simple::XML module to parse some info from an XML document. The wanted tags from the whole document, which is called data.xml are the following:
<?xml version='1.0'?> <PubmedArticle> <PMID>1766380</PMID> <Article PubModel="Print"> <Journal> <JournalIssue CitedMedium="Print"> <Volume>5</Volume> <Issue>9</Issue> <PubDate> <Year>1991</Year> <Month>Sep</Month> </PubDate> </JournalIssue> <ISOAbbreviation>Mol. Microbiol.</ISOAbbreviation> </Journal> <ArticleTitle>PhoP/PhoQ: macrophage-specific modulator +s of Salmonella virulence?</ArticleTitle> <Pagination> <MedlinePgn>2073-8</MedlinePgn> </Pagination> <AuthorList CompleteYN="Y"> <Author ValidYN="Y"> <LastName>Miller</LastName> <ForeName>S I</ForeName> <Initials>SI</Initials> </Author> <Author ValidYN="Y"> <LastName>Tsirigos</LastName> <ForeName>K T</ForeName> <Initials>KT</Initials> </Author> <Author ValidYN="Y"> <LastName>Dinous</LastName> <ForeName>A E</ForeName> <Initials>AE</Initials> </Author> </AuthorList> </Article> </PubmedArticle>
I read numerous tutorials and I managed to print all other tags apart from the details for the authors, that is <LastName>, <ForeName>, <Initials>. I used the following code:
#!/usr/bin/perl use XML::Simple; use Data::Dumper; $simple = XML::Simple->new; $data = $simple->XMLin('data.xml'); print $data->{PMID}; print $data->{Article}->{...}->{...};
I only have problem with the authors, because there can be more than one, contrary to all the other info contained in my xml... Can you help me please?

In reply to Perl & Simple::XML by Anonymous Monk

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.