First your "XML" file is not really XML. That makes it hard to show you some examples of what you can do with XML::Twig. Then it is not clear from your question what you mean by "tag". Is it just the start tag, the entire element or the text of the element? The difference between tag and element is an important one in XML.
Then if all you want is extract information from the file, you might want to have a look at xml_grep, which comes with XML::Twig. Have a look at the docs. If your files are not too big (ie XML::LibXML can load them in memory), you can also use xml_grep2, by the same author (xml_grep2), which has more complete XPath support (once again, at the cost of loading the entire document in memory).
Otherwise, the code below will print the start tags of the AI elements in AC elements with a n attribute of CCC:
XML::Twig->new( twig_handlers => { 'AC[@n="CCC"]//AI' => sub { print $_->start_tag, "\n"; }->parsefile( "my.xml");If you know that AI elements will allways be direct children of AC elements you can replace the '//' by a single '/'. If your XML file might be big, you could add a $_->purge at the end of the anonymous sub, in order to release some memory, or you could use the twig_roots option instead of twig_handlers.
I hope that gets you started.
In reply to Re: XML::Twig question
by mirod
in thread XML::Twig question
by thandi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |