how to print the output in certain order?



I am trying to extracting the data from xml and print it certain order but i couldnt able to print in that order


Input Xml



<xml>
<service>
<title>split xml</title>
<main>
<doc id="001">
<title>doc1</title>
<delt id="0001">
<title>delt1</title>
<text>num1</text>
</delt>
<delt id="0002-A">
<title>delt2</title>
<text>num1</text>
</delt>
</doc>
<doc id="002">
<title>doc2</title>
<delt id="0003">
<title>delt3</title>
<text>num1</text>
</delt>
<delt id="0004">
<title>delt4</title>
<text>num1</text>
</delt>
</doc>
</main>
</service>
</xml>


output printing in this order 0001 delt1 0002-A delt2 0003 delt3 0004 delt4


output needed



delt1 0001
delt2 0002-A
delt3 0003
delt4 0004


This is my Code



use File::Find;
use XML::LibXML;
use Data::Dumper;
my $path = "data.xml";
my $parser = XML::LibXML->new;
my $dom = $parser->parse_file($path) or die;
for my $sample ( $dom->findnodes('//delt/@id|//delt/title') ) {
print $sample->textContent(),"\t";
print "\n";

}


Thanks in advance


No comments:

Post a Comment