in reply to Re: XML - Escaping characters from database for XML
in thread XML - Escaping characters from database for XML

With XML::LibXML, you can get away without creating a document and element...

print XML::LibXML::Text->new('<&')->toString;

It's pretty easy to wrap that up into a function:

sub escape_xml { XML::LibXML::Text->new(shift)->toString } print escape_xml('<&');
perl -E'sub Monkey::do{say$_,for@_,do{($monkey=[caller(0)]->[3])=~s{::}{ }and$monkey}}"Monkey say"->Monkey::do'

Replies are listed 'Best First'.
Re^3: XML - Escaping characters from database for XML
by choroba (Cardinal) on May 28, 2012 at 14:46 UTC
    Well, yes. I was just discreetly suggesting creating the whole packages in XML::LibXML.