On Wed, Jul 14, 2010 at 4:33 PM, Barih Uri <[email protected]> wrote:

>
> According to your question I need to *"print $doc->toString" --> ** *to
> string and then to manipulate it in order to get the real XML
>

Just a small matter of terminology: a "real XML" *should* contain the
version information. You *are* getting a real XML.

What you want is to strip that XML from the version.


> Can you please give me real example for this
>

Both Gaal and I answered this already. I gave you an example of stripping
the version and Gaal simply said to remove the new lines in your
*input*before you create an XML from it.

Here is your script, including *strict*, some cleanups, and the comments
made by Gaal and myself:
-----
#!/usr/bin/perl

use strict;
use warnings;

use XML::LibXML;

local $XML::LibXML::skipXMLDeclaration = 1;

my $doc  = XML::LibXML::Document->new;
my $root = $doc->createElement('LEVEL1');

$doc->setDocumentElement($root);

my $system = $doc->createElement('LEVEL2');
$root->appendChild($system);

my $install = $doc->createElement('LEVEL3');
$system->appendChild($install);

my @myNames = `ls /var/tmp | grep FILE.xml | sed "s/.FILE.*//"`;
chomp @myNames;

foreach my $name (@myNames) {
    my $objVar = $doc->createElement('UnitType');
    $install->appendChild($objVar);

    $objVar->setAttribute( 'Name' ,          $name );
    $objVar->setAttribute( 'UponError',      Stop  );
    $objVar->setAttribute( 'ExecutionOrder', 1     );
}

my @xml_lines = split /\n/, $doc->toString;
shift @xml_lines;

my $stripped_doc = join "\n", @xml_lines;

open my $fh, '>', 'data.xml' or die "Can't open file: $!\n";
print {$fh} $stripped_doc;
close $fh;
-----

*Please* read our answers more clearly.

Sawyer.
_______________________________________________
Perl mailing list
[email protected]
http://mail.perl.org.il/mailman/listinfo/perl

Reply via email to