in reply to Re: how to remove an empty line from a xml file??
in thread how to remove an empty line from a xml file??

understood your point! thanks but I am unable to implement it in my script. could you please provide me with a prototype or an example script for my problem ???

  • Comment on Re^2: how to remove an empty line from a xml file??

Replies are listed 'Best First'.
Re^3: how to remove an empty line from a xml file??
by Corion (Patriarch) on Oct 01, 2016 at 08:46 UTC

      hi corion, that empty line is another child of $Item element I understood that but it is a XML::DOM::TEXT element. I don't know how to remove text nodes? don't write any code for me (y) but could you please tell me how to do that

      to remove a node I do : $parent_name=removeChild($node_name)but to remove text node what should I write in place of $node_name

        In the code you already wrote yourself, you use the method ->removeChild. This method is just as applicable for text nodes as it is for other nodes. Maybe now is a really good moment to familiarize yourself with XML and the DOM?

Re^3: how to remove an empty line from a xml file??
by beech (Parson) on Oct 01, 2016 at 09:00 UTC

    Hi,

    understood your point! thanks but I am unable to implement it in my script. could you please provide me with a prototype or an example script for my problem ???

    Can I see what you tried?

      hey was doing a silly mistake. tried the above code . it works! thanks for the help

      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); my @list=$item->getChildNodes; foreach my $list(@list) { if($list->getNodeType==TEXT_NODE) { $item->removeChild($list); } } } } } } $doc->setXMLDecl($doc->createXMLDecl('1.0','UTF-8')); $doc->printToFile("C:/perl/perl_tests/xmlin2.xml"); $doc->dispose;