| SRU documentation | Contained in the SRU distribution. |
SRU::Utils::XML - XML utility functions for SRU
use SRU::Utils::XML qw( escape );
return escape( $text );
This is a set of utility functions for use with XML data.
Creates an xml element named $tag containing escaped data ($text).
Similar to element, except that $text is not escaped.
Does minimal escaping on $text.
A shortcut method to create an xml-stylesheet declaration.
| SRU documentation | Contained in the SRU distribution. |
package SRU::Utils::XML; use strict; use warnings; use base qw( Exporter ); our @EXPORT_OK = qw( element elementNoEscape escape stylesheet );
sub element { my ($tag, $text) = @_; return '' if ! defined $text; return "<$tag>" . escape($text) . "</$tag>"; }
sub elementNoEscape { my ($tag, $text) = @_; return '' if ! defined $text; return "<$tag>$text</$tag>"; }
sub escape { my $text = shift || ''; $text =~ s/</</g; $text =~ s/>/>/g; $text =~ s/&/&/g; return $text; }
sub stylesheet { my $uri = shift; return qq(<?xml-stylesheet type='text/xsl' href="$uri" ?>); } 1;