Converting Disallowed Characters - Juniper JUNOS OS 10.3 - XML MANAGEMENT PROTOCOL GUIDE 6-30-2010 Manual

Junos xml management protocol guide
Hide thumbs Also See for JUNOS OS 10.3 - XML MANAGEMENT PROTOCOL GUIDE 6-30-2010:
Table of Contents

Advertisement

Junos 10.3 Junos XML Management Protocol Guide
216
use constant VALID_ACTIONS => "merge|replace|override";
output_usage() unless (VALID_ACTIONS =~ /$load_action/);

Converting Disallowed Characters

Scripts that handle configuration data usually accept and output the data either as Junos
XML tag elements or as formatted ASCII statements like those used in the Junos OS CLI.
As described in "XML and Junos XML Management Protocol Conventions Overview" on
page 9, certain characters cannot appear in their regular form in an XML document.
These characters include the apostrophe (
) and less-than (
) symbols, and the quotation mark (
<
might appear in formatted ASCII configuration statements, the script must convert the
characters to the corresponding predefined entity references.
The
script uses the
load_configuration.pl
predefined entity references for disallowed characters (the
includes similar code). The script first defines the mappings between the disallowed
characters and predefined entity references, and sets the variable
expression that contains all of the entity references, as follows:
my %escape_symbols = (
qq(") => '&quot;',
qq(>) => '&gt;',
qq(<) => '&lt;',
qq(') => '&apos;',
qq(&) => '&amp;'
);
my $char_class = join ("|", map { "($_)" } keys %escape_symbols);
The following code defines the
script. A detailed discussion of the subsections in the routine follows the complete code
sample.
sub get_escaped_text
{
my $input_file = shift;
my $input_string = "";
open(FH, $input_file) or return undef;
while(<FH>) {
my $line = $_;
$line =~ s/<configuration-text>//g;
$line =~ s/<\/configuration-text>//g;
$line =~ s/($char_class)/$escape_symbols{$1}/ge;
$input_string .= $line;
}
return "<configuration-text>$input_string</configuration-text>";
}
The first subsection of the preceding code sample reads in a file containing formatted
ASCII configuration statements:
sub get_escaped_text
{
my $input_file = shift;
'
), the ampersand (
"
get_escaped_text
get_escaped_text
subroutine for the
Copyright © 2010, Juniper Networks, Inc.
&
), the greater-than (
). Because these characters
subroutine to substitute
script
get_configuration.pl
$char_class
to a regular
load_configuration.pl
>

Advertisement

Table of Contents
loading

This manual is also suitable for:

Junos os

Table of Contents