XML:: LibXML PL/PerlU ( PL/Perl, XML:: LibXML plperl.on_init postgresql.conf) :
CREATE EXTENSION IF NOT EXISTS plperlu;
CREATE OR REPLACE FUNCTION replace_attribute(
xml xml,
attr text,
val text
) RETURNS XML LANGUAGE plperlu AS $$
my ($xml, $attr, $val) = @_;
use XML::LibXML;
my $dom = XML::LibXML->load_xml(string => $xml);
for my $elem ($dom->findnodes("*[\@$attr]")) {
$elem->setAttribute($attr => $val);
}
return $dom->serialize;
$$;
:
try=
'<foo id="blah">hi</foo>',
'id',
'whatever'
);
replace_attribute
-----------------------------
<foo id="whatever">hi</foo>+
XPath findnodes(), .