in reply to Re^2: copy XML elements from one file to another
in thread copy XML elements from one file to another

how I can view my output file? I don't see any generated output files
You can print directly to a file using the toFile() method. Add the following lines to the example given above:
$new->addChild($features); my $filename = 'new.xml'; my $ok = $new->toFile($filename,2);
I assume "parser" in this case will be parsing the source file (where im getting my input from) right?
Yes, you would set up the parser like this, probably in a loop to go through each file:
my $file = 'file-1.xml'; my $parser = XML::LibXML->load_xml(location => $file);

Replies are listed 'Best First'.
Re^4: copy XML elements from one file to another
by Anonymous Monk on Nov 25, 2013 at 23:06 UTC

    Thanks again for the help but unfortunately I only got the following in my output file when using $new->toFile('fileName')
    <?xml version="1.0" encoding="utf-8"?>
    I have tried this before reading your reply. But I got the same result. printing my results did help a bit just for debugging purposes. Also tried piping my print statements to a file but the formatting was not good and the text was from bottom to top
    I just need to get this step done by seeing a nice formatted output so I can start playing around with the code and get what I want. Thanks again

      I only got the following in my output file...
      <?xml version="1.0" encoding="utf-8"?>
      Did you include the line $new->addChild($features); ?
      a nice formatted output
      Did you include the format argument 2 in $new->toFile($filename,2) ? You can also print $new->toString(2) when debugging.
Re^4: copy XML elements from one file to another
by Anonymous Monk on Nov 26, 2013 at 05:11 UTC

    I did actually include that line. You mean the same line you mentioned in your code in your first response right ?
    I used your code exactly with tweaking few things like file names. The print is showing that its working overall but file output is unfortunately not
    btw when I used your suggestion my $ok = $new->toFile($file-name,2) I got I/O invalid argument. I managed to get it work but as I said still doesn't show anything other than what I mentioned.
    again thanks for your help

      Note that $file-name is not a valid variable name in Perl. I recommend that you start using the strict pragma in your program, which will catch such mistakes.

      Please show the code that you have now, it will be easier to debug if we can see it.