I need to parse the following XML file. Absolute beginner, doesn't know how. These are some questions that I need to answer.

List All <AI> tags within the <AC n="CCC">
List only <AI> tags and its <Desc> within the <AC n="CCC">
List all <ID> tags and its <Desc> within <AI n="AAA">
etc...

This means that I need to extract differing info depending on the command line given on the command line:

Here's the 'modified' XML file:

<World n="earth" > <Space n="XXX" > <CL n="XXX"> <Desc>CL desc</Des> <Other/> <AC n="AAA" set="n"> <Desc>AC AAA desc</Desc> <AI n="AAA" set="n"> <Desc>AI AAA desc</Desc> <ID n="AAA" set="y"> <Desc>AAA ID desc</Desc> <What>What AAA ID </What> <AR>ID_aaa</AR> </ID> <ID n="BBB" set="y"> <Desc>BBB ID desc</Desc> <What>What BBB ID </What> <AR>ID_bbb</AR> </ID> </AI> <AI n="BBB" set="y"> <Desc>AI BBB desc</Desc> <ID n="AAA" set="y"> <Desc>AAA ID desc</Desc> <What>What AAA ID </What> <AR>ID_aaa</AR> </ID> </AI> </AC> <AC n="CCC" set="y"> <AI n="AAA" set="n"> <Desc>AI AAA desc</Desc> <ID n="AAA" set="y"> <Desc>AAA ID desc</Desc> <What>What AAA ID </What> <AR>ID_aaa</AR> </ID> </AI> <AI n="AAA" set="n"> <Desc>AI AAA desc</Desc> <ID n="AAA" set="y"> <Desc>AAA ID desc</Desc> <What>What AAA ID </What> <AR>ID_aaa</AR> </ID> </AI> </AC> <CL n="XXX"> <Space n="XXX" > <World n="earth" >
tks thandi

In reply to XML::Twig question by thandi

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.