Reputation: 47
I am convert xml to xml file, I try to convert text as for source. I am currently using xml::Twig and I need output without any change in xml.
I Tried:
xml:
<book>
<book-meta>
<book-id pub-id-type="doi">98568</book-id>
<copyright-statement>Copyright © 1999 Relati</copyright-statement>
<imprint-text type="PublisherInfo">This edition published in the Taylor & 2002.</imprint-text>
</book-meta>
</book>
Script:
use strict;
use XML::Twig;
use XML::Xpath;
open(my $output , '>', "Output.xml") || die "can't open the Output $!\n";
my $xml_twig_content = XML::Twig->new(
twig_handlers => {
keep_atts_order => 1,
keep_encoding => 1,
},
pretty_print => 'indented',
);
$xml_twig_content->parsefile('sample.xml');
$xml_twig_content->print($output);
output:
<book>
<book-meta>
<book-id pub-id-type="doi">98568</book-id>
<copyright-statement>Copyright © 1999 Relati</copyright-statement>
<imprint-text type="PublisherInfo">This edition published in the Taylor & 2002.</imprint-text>
</book-meta>
</book>
I need output:
<book>
<book-meta>
<book-id pub-id-type="doi">98568</book-id>
<copyright-statement>Copyright © 1999 Relati</copyright-statement>
<imprint-text type="PublisherInfo">This edition published in the Taylor & 2002.</imprint-text>
</book-meta>
</book>
How can i need as source without any changes.
Upvotes: 2
Views: 150
Reputation: 16161
There is a problem in your new
statement: keep_encoding
and keep_atts_order
parameters are declared as twig_handlers
. I don't think that's what you want, since the only thing this does is to die as soon as an element named keep_atts_order
or keep_encoding
is found in the XML.
I think this is more like what you had in mind:
my $xml_twig_content = XML::Twig->new( keep_atts_order => 1,
keep_encoding => 1,
pretty_print => 'indented',
);
Upvotes: 1