Juniper JUNOS OS 10.3 - XML MANAGEMENT PROTOCOL GUIDE 6-30-2010 Manual page 253

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

Copyright © 2010, Juniper Networks, Inc.
my $config_node;
my $top_tag = "configuration";
$top_tag .= "-text" if $text_mode;
if ($config->getTagName( ) eq $top_tag) {
$config_node = $config;
} else {
print "# unknown response component ", $config->getTagName( ), "\n";
}
The subroutine then uses several nested
the XML DOM tree exists and contains data:
if ( $config_node && $config_node ne "" ) {
... actions if XML DOM tree contains data ...
}
else {
print "ERROR: empty configuration data for $hostname\n";
}
If the XML DOM tree contains data, the subroutine verifies that the output file can be
opened for writing:
if ( open OUTPUTFILE, ">$filename" ) {
... actions if output file is writable ...
}
else {
print "ERROR: could not open output file $filename\n";
}
If the output file can be opened for writing, the script writes the configuration data into
it. If the user requested Junos XML tag elements—the user did not include the
on the command line, so the
the string
<?xml version=1.0?>
function (defined in the
toString
in the XML DOM tree on a line in the output file:
if (!$text_mode) {
print OUTPUTFILE "<?xml version=\"1.0\"?>\n";
print OUTPUTFILE $config_node->toString( ), "\n";
If the user requested formatted ASCII text, the script invokes the
functions (defined in the
XML::DOM
line in the output file. The script substitutes predefined entity references for disallowed
characters (which are defined in the
file, and closes the output file. (For information about defining the
contain the set of disallowed characters, see "Converting Disallowed Characters" on
page 216.)
} else {
my $buf = $config_node->getFirstChild( )->toString( );
$buf =~ s/($char_class)/$escapes{$1}/ge;
print OUTPUTFILE "$buf\n";
Chapter 9: Writing Junos XML Protocol Perl Client Applications
if
statements. The first
$text_mode
variable does not have a value—the script writes
as the first line in the output file, and then invokes the
module) to write each Junos XML tag element
XML::DOM
module) to write the content of each tag on its own
%escapes
hash), writes the output to the output
if
statement verifies that
-t
option
and
getFirstChild
toString
hash to
%escapes
231

Advertisement

Table of Contents
loading

This manual is also suitable for:

Junos os

Table of Contents