How can I escape text for an XML document in Perl?

前端 未结 9 1192
长发绾君心
长发绾君心 2021-01-01 06:53

Anyone know of any Perl module to escape text in an XML document?

I\'m generating XML which will contain text that was entered by the user. I want to correctly handl

9条回答
  •  长情又很酷
    2021-01-01 06:57

    Use

    XML::Generator

    require XML::Generator;

    my $xml = XML::Generator->new( ':pretty', escape => 'always,apos' );

    print $xml->h1( " &< >non-html plain text< >&" );

    which will print all content inside the tags escaped (no conflicts with the markup).

提交回复
热议问题