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->next_elt($info) )<br> {<br>
$elt->set_remove_cdata(1);<br> $elt->set_pretty_print("record"); # print one field per line<br> printf "%s\n", $elt->sprint;<br> }<br>}<br>
<br>$xml = new XML::Twig(<br> TwigHandlers => {<br> XML_DIZ_INFO => \&info,<br> }<br>);<br><br># Parse the XML<br>$xml->parsefile('sample.xml');<br><br>************************<br>
<br>sample.xml<br>-----------------<br><?xml version="1.0" ?><br><XML_DIZ_INFO><br> <MASTER_PAD_VERSION_INFO><br> <MASTER_PAD_VERSION>1.0</MASTER_PAD_VERSION><br>
<MASTER_PAD_EDITOR>Master Editor here</MASTER_PAD_EDITOR><br> <MASTER_PAD_INFO>information would go here </MASTER_PAD_INFO><br> </MASTER_PAD_VERSION_INFO><br>
<Company_Info><br> <Company_Name>Moyea Software Co., Ltd.</Company_Name><br> <Country>China</Country><br> <Company_WebSite_URL><a href="http://www.whatever.com">http://www.whatever.com</a></Company_WebSite_URL><br>
<Contact_Info><br> <Author_First_Name>Bob</Author_First_Name><br> <Author_Last_Name>King</Author_Last_Name><br> <Author_Email><a href="mailto:product@moyea.com">product@moyea.com</a></Author_Email><br>
</Contact_Info><br> </Company_Info><br></XML_DIZ_INFO><br><br>============================================<br>The following is the output I get. After the closing </Company_Info> it should stop.<br>
============================================<br><br> <MASTER_PAD_VERSION_INFO><br> <MASTER_PAD_VERSION>1.0</MASTER_PAD_VERSION><br> <MASTER_PAD_EDITOR>Master Editor here</MASTER_PAD_EDITOR><br>
<MASTER_PAD_INFO>information would go here </MASTER_PAD_INFO><br> </MASTER_PAD_VERSION_INFO><br><br> <MASTER_PAD_VERSION>1.0</MASTER_PAD_VERSION><br>1.0<br><br> <MASTER_PAD_EDITOR>Master Editor here</MASTER_PAD_EDITOR><br>
Master Editor here<br><br> <MASTER_PAD_INFO>information would go here </MASTER_PAD_INFO><br>information would go here <br><br> <Company_Info><br> <Company_Name>Moyea Software Co., Ltd.</Company_Name><br>
<Country>China</Country><br> <Company_WebSite_URL><a href="http://www.whatever.com">http://www.whatever.com</a></Company_WebSite_URL><br> <Contact_Info><br> <Author_First_Name>Bob</Author_First_Name><br>
<Author_Last_Name>King</Author_Last_Name><br> <Author_Email><a href="mailto:product@moyea.com">product@moyea.com</a></Author_Email><br> </Contact_Info><br> </Company_Info><br>
<br> <Company_Name>Moyea Software Co., Ltd.</Company_Name><br>Moyea Software Co., Ltd.<br><br> <Country>China</Country><br>China<br><br> <Company_WebSite_URL><a href="http://www.whatever.com">http://www.whatever.com</a></Company_WebSite_URL><br>
<a href="http://www.whatever.com">http://www.whatever.com</a><br><br> <Contact_Info><br> <Author_First_Name>Bob</Author_First_Name><br> <Author_Last_Name>King</Author_Last_Name><br>
<Author_Email><a href="mailto:product@moyea.com">product@moyea.com</a></Author_Email><br> </Contact_Info><br><br> <Author_First_Name>Bob</Author_First_Name><br>Bob<br><br> <Author_Last_Name>King</Author_Last_Name><br>
King<br><br> <Author_Email><a href="mailto:product@moyea.com">product@moyea.com</a></Author_Email><br><a href="mailto:product@moyea.com">product@moyea.com</a><br><br><br>