How to remove an empty line which is created when i deleted a element from my xml file?

Joined
Oct 1, 2016
Messages
1
Reaction score
0
MY CODE IS :


use strict;
use warnings;
use Data:: Dumper;
use XML:: DOM;

my $parser=new XML:: DOM:: Parser;

my $doc=$parser->parsefile('C:\perl\perl_tests\xmlin2.xml') or die$!;
my $root=$doc->getDocumentElement();

my @address=$root->getElementsByTagName("address");
foreach my $address(@address)
{
if($address->getAttribute("name") eq "Joey")
{
if(my $item=$address->getElementsByTagName("item")->item(0))
{
if(my $data=$item->getElementsByTagName("data")->item(0))
{
$item->removeChild($data);
}
}
}
}
$doc->setXMLDecl($doc->createXMLDecl('1.0','UTF-8'));
$doc->printToFile("C:/perl/perl_tests/xmlin2.xml");
$doc->dispose;





I use XML:: DOM to parse xml file and do modifications in it . when I deleted an element named "data" it created an empty line (although data element got deleted) but I want to remove this empty line from my xml document. how can I do it ? any suggestions or solutions are welcome?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,733
Messages
2,569,440
Members
44,830
Latest member
ZADIva7383

Latest Threads

Top