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

前端 未结 9 1185
长发绾君心
长发绾君心 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 07:19

    After checking out XML::Code as recommended by Krish I found that this can be done using the XML::Code text() function. E.g.,

    use XML::Code;
    my $text = new XML::Code('=');
    $text->set_text(q{> & < " ' "});
    print $text->code(); # prints > < & " ' "
    

    Passing '=' creates a text node which when printed doesn't contain tags. Note: this only works for text data. It wont correctly escape attributes.

提交回复
热议问题