tarun28jain has asked for the wisdom of the Perl Monks concerning the following question:

I have an object of XML::LibXML named $doc
It has some xml data for a query.
Now i need to replace all the /u2028 and /u2029 characters i.e. newline characters present in this data with some other text.

I tried this

$doc->toString =~ s/\u2028\u2029//g; $doc->toFH( $file_handle, 1 );
but received an error as
[error] Can't modify non-lvalue subroutine call at .....
$doc->toString is printing the complete xml present in the object correctly.

Replies are listed 'Best First'.
Re: XML::LibXML library issue
by choroba (Cardinal) on Dec 09, 2013 at 12:25 UTC
    First, store the output to a variable. Then apply the substitution (untested):
    my $out = $doc->toString; $out =~ s/\u2028\u2029//g;

    BTW, see <pre> Versus <code> Tags and stop using <pre> tags for normal text.

    لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      I need to write this modified data in a response file. Previously it was done using

       $doc->toFH( $file_handle, 1 );

      Can i somehow write this modified data back in $doc object from $out so that response file does not have these removed characters in them.

        Sure. See the documentation of print on how to do it.
        لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ