- 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?
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?