All -<br><br>Figured out the problem.  Sterling Hanenkamp got me going in the right direction.<br><br>Anyway... I was using an abstract example to ask my question, so here is an explanation and my actual code.<br><br>I am working with the Qualys API and I wanted to pull all scan data back from Qualys so that I can store and mashup the data against other data sources.<br>

<br>The DTD for the Qualys xml is:  <a href="https://qualysapi.qualys.com/scan-1.dtd" target="_blank">https://qualysapi.qualys.com/scan-1.dtd</a>  (This will give you the structure of the XML file)<br><br>Here is the basic code that I ended up with.  This works on the xml file after being retrieved from Qualys.<br>

<br><br>*************************************************<br><div id=":1v7" class="ii gt">#!/usr/bin/perl
 -w<br><br># Indentation style: 1 tab = 4 spaces<div class="im"><br><br>require
 XML::Twig;<br><br>sub info {<br>        my ($xml, $info) = @_; <br>       
 my $elt = $info;<br></div>
        if ($elt-&gt;is_elt =~ m/(VULN|SERVICE|INFO|PRACTICE)/) {<br>           
 printf &quot;VALUE: %s \n&quot;, $elt-&gt;parent-&gt;parent-&gt;parent-&gt;att(&quot;value&quot;);<br>           
 printf &quot;ENT: %s \n&quot;, $elt-&gt;is_elt;<br>
        }   <br><br>        if ($elt-&gt;is_elt =~ 
m/(OS|NETBIOS_HOSTNAME)/) {<br>                printf &quot;VALUE: %s \n&quot;, 
$elt-&gt;parent-&gt;att(&quot;value&quot;);<br>                printf &quot;ENT: %s 
\n&quot;, $elt-&gt;is_elt;<br>
                printf &quot;%s\n&quot;, $elt-&gt;text;<div class="im"><br>       
 }   <br>        while ($elt= $elt-&gt;next_elt($info) )<br>        {   <br></div>               
 my $localname = $elt-&gt;local_name;<br>                if ($localname 
ne &#39;#CDATA&#39; &amp;&amp; $localname ne &#39;#PCDATA&#39;) {<br>
                    printf &quot;%s: &quot;, $localname;<br>                    
printf &quot;%s\n&quot;, $elt-&gt;text;<br>                }   <br>        }   <br>       
 printf &quot;\n\n&quot;;<br>}<br><br>#===================================================<br>
#Main program section<div class="im"><br><br>$xml = new XML::Twig(<br>       
 TwigHandlers =&gt; {<br></div>                SERVICE             =&gt;
 \&amp;info,<br>                VULN                =&gt; \&amp;info,<br>               
 OS                  =&gt; \&amp;info,<br>
                NETBIOS_HOSTNAME    =&gt; \&amp;info,<br>               
 INFO                =&gt; \&amp;info,<br>                
PRACTICE            =&gt; \&amp;info,<br>                
HEADER              =&gt; \&amp;info,<br>
                #_all_       =&gt; \&amp;info,                        
 # not using _all_ to ignore the toplevel SCAN tag<br>        },  <br>       
 error_context =&gt; 1,<div class="im"><br>);<br><br># Parse the XML<br>$xml-&gt;parsefile(&#39;sample.xml&#39;);<br>
<br></div>******************************************************************</div><br><br><div class="gmail_quote">On Fri, Jun 25, 2010 at 7:31 PM, Daryl Fallin <span dir="ltr">&lt;<a href="mailto:darylvf@gmail.com">darylvf@gmail.com</a>&gt;</span> wrote:<br>

<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">Hi All ....<br><br>I have been trying to work with XML::Twig lately to parse an xml file.<br>

<br>I just want to dump every element/Tag of the xml file.  But my while loops seems to be doing something weird or its the way that XML::Twig is working, not sure, but I get duplicate information from the original XML file.  Its like it is running part of the while loop twice.<br>


<br>I know there are other modules that I could use but I am using XML::Twig for other parts of what will be a larger program and I want the chunking that XML:Twig allows.<br><br>Any help would be greatly appreciated.<br>


<br>Here is my sample code:<br><br>#!/usr/bin/perl -w<br><br>require XML::Twig;<br><br>sub info {<br>        my ($xml, $info) = @_;<br>        my $elt = $info;<br>        while ($elt= $elt-&gt;next_elt($info) )<br>        {<br>


                $elt-&gt;set_remove_cdata(1);<br>                $elt-&gt;set_pretty_print(&quot;record&quot;);  # print one field per line<br>                printf &quot;%s\n&quot;, $elt-&gt;sprint;<br>        }<br>}<br>


<br>$xml = new XML::Twig(<br>        TwigHandlers =&gt; {<br>                XML_DIZ_INFO       =&gt; \&amp;info,<br>        }<br>);<br><br># Parse the XML<br>$xml-&gt;parsefile(&#39;sample.xml&#39;);<br><br>************************<br>


<br>sample.xml<br>-----------------<br>&lt;?xml version=&quot;1.0&quot; ?&gt;<br>&lt;XML_DIZ_INFO&gt;<br>        &lt;MASTER_PAD_VERSION_INFO&gt;<br>                &lt;MASTER_PAD_VERSION&gt;1.0&lt;/MASTER_PAD_VERSION&gt;<br>


                &lt;MASTER_PAD_EDITOR&gt;Master Editor here&lt;/MASTER_PAD_EDITOR&gt;<br>                &lt;MASTER_PAD_INFO&gt;information would go here &lt;/MASTER_PAD_INFO&gt;<br>        &lt;/MASTER_PAD_VERSION_INFO&gt;<br>


        &lt;Company_Info&gt;<br>                &lt;Company_Name&gt;Moyea Software Co., Ltd.&lt;/Company_Name&gt;<br>                &lt;Country&gt;China&lt;/Country&gt;<br>                &lt;Company_WebSite_URL&gt;<a href="http://www.whatever.com" target="_blank">http://www.whatever.com</a>&lt;/Company_WebSite_URL&gt;<br>


                &lt;Contact_Info&gt;<br>                        &lt;Author_First_Name&gt;Bob&lt;/Author_First_Name&gt;<br>                        &lt;Author_Last_Name&gt;King&lt;/Author_Last_Name&gt;<br>                        &lt;Author_Email&gt;<a href="mailto:product@moyea.com" target="_blank">product@moyea.com</a>&lt;/Author_Email&gt;<br>


                &lt;/Contact_Info&gt;<br>        &lt;/Company_Info&gt;<br>&lt;/XML_DIZ_INFO&gt;<br><br>============================================<br>The following is the output I get.  After the closing &lt;/Company_Info&gt; it should stop.<br>


============================================<br><br>  &lt;MASTER_PAD_VERSION_INFO&gt;<br>    &lt;MASTER_PAD_VERSION&gt;1.0&lt;/MASTER_PAD_VERSION&gt;<br>    &lt;MASTER_PAD_EDITOR&gt;Master Editor here&lt;/MASTER_PAD_EDITOR&gt;<br>


    &lt;MASTER_PAD_INFO&gt;information would go here &lt;/MASTER_PAD_INFO&gt;<br>  &lt;/MASTER_PAD_VERSION_INFO&gt;<br><br>    &lt;MASTER_PAD_VERSION&gt;1.0&lt;/MASTER_PAD_VERSION&gt;<br>1.0<br><br>    &lt;MASTER_PAD_EDITOR&gt;Master Editor here&lt;/MASTER_PAD_EDITOR&gt;<br>


Master Editor here<br><br>    &lt;MASTER_PAD_INFO&gt;information would go here &lt;/MASTER_PAD_INFO&gt;<br>information would go here <br><br>  &lt;Company_Info&gt;<br>    &lt;Company_Name&gt;Moyea Software Co., Ltd.&lt;/Company_Name&gt;<br>


    &lt;Country&gt;China&lt;/Country&gt;<br>    &lt;Company_WebSite_URL&gt;<a href="http://www.whatever.com" target="_blank">http://www.whatever.com</a>&lt;/Company_WebSite_URL&gt;<br>    &lt;Contact_Info&gt;<br>      &lt;Author_First_Name&gt;Bob&lt;/Author_First_Name&gt;<br>


      &lt;Author_Last_Name&gt;King&lt;/Author_Last_Name&gt;<br>      &lt;Author_Email&gt;<a href="mailto:product@moyea.com" target="_blank">product@moyea.com</a>&lt;/Author_Email&gt;<br>    &lt;/Contact_Info&gt;<br>  &lt;/Company_Info&gt;<br>


<br>    &lt;Company_Name&gt;Moyea Software Co., Ltd.&lt;/Company_Name&gt;<br>Moyea Software Co., Ltd.<br><br>    &lt;Country&gt;China&lt;/Country&gt;<br>China<br><br>    &lt;Company_WebSite_URL&gt;<a href="http://www.whatever.com" target="_blank">http://www.whatever.com</a>&lt;/Company_WebSite_URL&gt;<br>


<a href="http://www.whatever.com" target="_blank">http://www.whatever.com</a><br><br>    &lt;Contact_Info&gt;<br>      &lt;Author_First_Name&gt;Bob&lt;/Author_First_Name&gt;<br>      &lt;Author_Last_Name&gt;King&lt;/Author_Last_Name&gt;<br>


      &lt;Author_Email&gt;<a href="mailto:product@moyea.com" target="_blank">product@moyea.com</a>&lt;/Author_Email&gt;<br>    &lt;/Contact_Info&gt;<br><br>      &lt;Author_First_Name&gt;Bob&lt;/Author_First_Name&gt;<br>

Bob<br><br>      &lt;Author_Last_Name&gt;King&lt;/Author_Last_Name&gt;<br>
King<br><br>      &lt;Author_Email&gt;<a href="mailto:product@moyea.com" target="_blank">product@moyea.com</a>&lt;/Author_Email&gt;<br><a href="mailto:product@moyea.com" target="_blank">product@moyea.com</a><br><br><br>
</blockquote></div><br>