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

Thanks for your help. I was trying your soltuion but I cant figure out the follwoing:
1. how I can view my output file? I don't see any generated output files
2. I assume "parser" in this case will be parsing the source file (where im getting my input from) right ?

I understand whats going on with your code but im just lost with where I see my results. I have tried multiple times but couldn't see any generated output file.
tried different examples using the same approach but still cant figure out how to get my output file.

  • Comment on Re^2: copy XML elements from one file to another

Replies are listed 'Best First'.
Re^3: copy XML elements from one file to another
by tangent (Parson) on Nov 25, 2013 at 18:47 UTC
    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);

      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.

      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.