I seem to be spinning my wheels and coding myself into a corner. I am learning XML::Twig and trying to traverse an xml file and gather all children of root element into array along with all siblings and attributes; separated for each child of root. For example, in the following xml file I would like to place each class in a separate array along with all_members, private_members, public_methods, etc. and all their associated siblings and attributes. I can do it easily with XML::Parser using the Start method which passes my( $expat, $element, %attrs ) = @_; to my subroutine. Would like to do this with XML::Twig but have not mastered its syntactical usage, yet. If someone has already done this, please advise and provide sample.
<myroot> <classes name="Panoply::AccessLogic"> <all_members name="accessLogic" protection="public" scope="Panoply +::AccessLogic" virtualness="non_virtual" /> <all_members name="DBUS" protection="public" scope="Panoply::Acces +sLogic" virtualness="non_virtual" /> <all_members name="DDR_VIA_JTAG" protection="public" scope="Panopl +y::AccessLogic" virtualness="non_virtual" /> <all_members name="DEFAULT" protection="public" scope="Panoply::Ac +cessLogic" virtualness="non_virtual" /> <brief></brief> <detailed> <doc type="text">Models the access logic</doc> </detailed> <includes name="AccessLogic.hpp" local="no" /> <private_members> <members name="m_accessLogic" kind="variable" protection="privat +e" static="no" type="AccessLogicTypes" virtualness="non_virtual"> </members> <members name="m_handledErrors" kind="variable" protection="priv +ate" static="no" type="HandledErrors" virtualness="non_virtual"> </members> </private_members> <public_methods> <members name="accessLogic" const="yes" kind="function" protecti +on="public" static="no" type="AccessLogicTypes" virtualness="non_virt +ual" volatile="no"> <brief></brief> <detailed> <doc type="text">Gets the current access logic for...</doc> </detailed> </members> <members name="AccessLogic" const="no" kind="function" protectio +n="public" static="no" virtualness="non_virtual" volatile="no"> <parameters declaration_name="accessLogic" default_value="DEFA +ULT" type="AccessLogicTypes" /> <parameters declaration_name="handledErrors" default_value="Ha +ndledErrors::ALL" type="const HandledErrors &amp;" /> </members> </public_methods> <public_typedefs> <members name="AccessLogicTypes" kind="enum" protection="public" + static="no" virtualness="non_virtual"> <values name="DEFAULT"> </values> <values name="IO_CF8_CFC"> </values> </members> </public_typedefs> </classes> <classes name="Panoply::Details::ActionBatch"> <brief></brief> <detailed></detailed> <includes name="PlatformActionBatch.hpp" local="no" /> </classes> <files name="panoplydoc.hpp"> <detailed></detailed> </files> <files name="PanoplyVersion.hpp"> <brief></brief> <includes name="string" /> <variables> <members name="LIBRARY_VERSION" initializer="&quot;0.1.9&quot;" +kind="variable" static="no" type="const std::string"> </members> <members name="BUILD_DATE" initializer="&quot;00/00/0000&quot;" +kind="variable" static="no" type="const std::string"> </members> </variables> </files> </myroot>

In reply to XML::Twig traversing tree and storing in an array by jccunning

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.