Re: [XML-Twig] Problems with Newlines in print

Johannes Kilian <[email protected]>
Newsgroups gmane.comp.lang.perl.xml
Organization VITRONIC Dr.-Ing. Stein Bildverarbeitungssysteme GmbH
Message-ID <[email protected]>
Forgot to mention:
* Perl 5.8.8 (ActiveState) with XML::Twig 3.32
* Trying to reproduce behaviour outside my script failed (yet) - but the
problematic XML-File is read  and handled as shown in code snippet ...

Johannes



Johannes Kilian schrieb:
> Hi,
>
> I've a quite complex program, which manipulates an XML-Config file on
> base of other XML-Configfiles.
> Reading the XML-file and printing it again produces an output-XML-file
> which contains newlines, which I don't want to have in my output ...
> (It's very annoying,, since the considered XML-File is very often
> rewritten and each time new newlines are inserted - so it's growing all
> the time ...) How can I avoid the new newlines?
> Any help welcome ...
>
> Thanks in advance
> Johannes
>
>
> What I basically do is:
> ---- SNIP ----
> my $twig1 = XML::Twig->new();
> $twig1->parsefile(...);
> my $twig2 = XML::Twig->new();
> $twig1->parsefile(...);
> ... loop over nodes in $twig1 and $twig2...
>     my $twig = XML::Twig->new(pretty_print => 'indented', empty_tags =>
> 'normal', comments => 'keep', keep_encoding => 1, keep_atts_order => 1);
>     $twig->parsefile($file); # see contents below
>     my @nodeList;
>     my $strXpath = ... contents of node of twig1...;
>     @nodeList = $twig->find_nodes($strXpath);
>     if (!@nodeList) {
>       print ("XPath <" . $strXpath . "> does not exist\n");
>       exit;
>     }
>     my $srcVal = $nodeList[0]->text;
>     my $destVal = ... contents of node of twig2...;
>     print "Replace value <" . $srcVal . "> with <" . $destVal . ">\n";
>     $nodeList[0]->set_text($destVal);
>
>     $twig->print_to_file( 'test.xml' );
> ... endloop ...
> ----------------
>
> This codesnippet occurs within a loop, in which I read some
> node-contents of the other XML-files (which provide basically the
> contents of the variables $strXpath and $destVal above - the value of
> $strXpath has no influence in this contents)
>
> What occurs is, that the resulting output has a few NEW newlines (to
> make them visible I replaced the new newlines by 'XXXXX'), which haven't
> been there before:
>
> ------ INPUT -----
> ...
>       <!--A>
>         <B>
>           <C>XXX1</C>
>           <D>0</D>
>         </B>
>         <B>
>           <C>XXX2</C>
>           <D>1</D>
>         </B>
>       </A-->
>       <F>false</F>
>       <E>
>         ../log/Out.log
>       </E>
> ...
> -----------------------
> ------ Output -------
> ...
>       <!--A>
> XXXXX
>         <B>
> XXXXX
>           <C>XXX1</C>
> XXXXX
>           <D>0</D>
> XXXXX
>         </B>
> XXXXX
>         <B>
> XXXXX
>           <C>XXX2</C>
> XXXXX
>           <D>1</D>
> XXXXX
>         </B>
> XXXXX
>       </A-->
>       <F>false</F>
>       <E>
> XXXXX
>          ../log/Out.log
> XXXXX
>       </E>
> ...
> ---------
> _______________________________________________
> Perl-XML mailing list
> [email protected]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
>
>   

_______________________________________________
Perl-XML mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.