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

Discussion in 'Perl' started by Ankit Tayal, Oct 1, 2016.

  1. Ankit Tayal

    Ankit Tayal

    Joined:
    Oct 1, 2016
    Messages:
    1
    Likes Received:
    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?
     
    Ankit Tayal, Oct 1, 2016
    #1
    1. Advertisements

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Lukas
    Replies:
    3
    Views:
    1,157
    spiff
    Nov 10, 2005
  2. kaushikshome
    Replies:
    4
    Views:
    1,120
    kaushikshome
    Sep 10, 2006
  3. Chumley the Walrus
    Replies:
    2
    Views:
    549
    Tom Gosselin
    Aug 10, 2004
  4. Moh

    I need a VHDL code

    Moh, Jun 8, 2016, in forum: VHDL
    Replies:
    0
    Views:
    531
  5. alxcam8
    Replies:
    0
    Views:
    532
    alxcam8
    Jun 29, 2016
  6. Anwesa Roy
    Replies:
    0
    Views:
    581
    Anwesa Roy
    Aug 22, 2016
  7. Abhinn

    how to change font syle in bluej

    Abhinn, Aug 28, 2016, in forum: Introductions
    Replies:
    0
    Views:
    569
    Abhinn
    Aug 28, 2016
  8. Mikaila

    Help with my program??

    Mikaila, Sep 30, 2016, in forum: C Programming
    Replies:
    1
    Views:
    796
    bmitchell2407
    Oct 10, 2016
Loading...