Parse the Junos XML Protocol Server Response
In a Junos XML protocol session with a device running
Junos OS, a client application sends RPCs to the Junos XML protocol
server to request information from and manage the configuration on
the device. The Junos XML protocol server encloses its response to
each client request in a separate pair of opening <rpc-reply>
and closing </rpc-reply>
tags. Each
response constitutes a well-formed XML document.
<rpc-reply xmlns:junos=""http://xml.juniper.net/junos/release/junos""> <!-- tag elements representing a response --> </rpc-reply>
The xmlns:junos
attribute in the
opening <rpc-reply>
tag defines the
default namespace for the enclosed Junos XML tag elements that are
qualified by the junos:
prefix. The release variable in the URI represents the Junos OS release
that is running on the Junos XML protocol server device, for example 20.4R1
The <rpc-reply>
tag element occurs
only within the <junoscript>
element.
Client applications must include code for parsing the stream of response
tag elements coming from the Junos XML protocol server, either processing
them as they arrive or storing them until the response is complete.
The Junos XML protocol server returns three classes of responses:
Operational Responses
Operational responses are responses to requests for information about the status of a switching, routing, or security platform. They correspond to the output from CLI operational commands.
The Junos XML API defines response tag elements for all defined
operational request tag elements. For example, the Junos XML protocol
server returns the information requested by the <get-interface-information>
tag in a response tag called <interface-information>
, and returns the information requested by the <get-chassis-inventory>
tag in a<chassis-inventory>
response
tag called <chassis-inventory>
.
Operational responses also can be returned in formatted ASCII, which
is enclosed within an output
element, or
in JSON format. For more information about formatting operational
responses see Specifying the Output Format
for Operational Information Requests in a Junos XML Protocol Session.
The following sample response includes information about
the interface ge-2/3/0. The namespace indicated by the xmlns
attribute in the opening <interface-information>
tag contains interface information for Junos OS Release 20.4.
<rpc-reply xmlns:junos="http://xml.juniper.net/junos/20.4R1/junos"> <interface-information xmlns="http://xml.juniper.net/junos/20.4R1/junos-interface"> <physical-interface> <name>ge-2/3/0</name> <!-- other data tag elements for the ge-2/3/0 interface --> </physical-interface> </interface-information> </rpc-reply>
For more information about the xmlns
attribute and contents of operational response tag elements, see Requesting Operational Information Using the Junos
XML Protocol. For a summary of operational response tag
elements, see the Junos XML API Operational Developer Reference.
Configuration Information Responses
Configuration information responses are
responses to requests for information about the device’s current
configuration. The Junos XML API defines a tag element for every container
and leaf statement in the configuration hierarchy. You can instruct
the server to return configuration data in different formats including
Junos XML elements, formatted ASCII, Junos OS set
commands,
or JSON. If you do not specify a format, the default is XML. For more
information about formatting configuration information responses see Specifying the Output Format for Configuration Data
in a Junos XML Protocol Session.
The following sample response includes the information
at the [edit system login]
hierarchy level in
the configuration hierarchy. For brevity, the sample shows only one
user defined at this level.
<rpc-reply xmlns:junos="URL"> <configuration> <system> <login> <user> <name>admin</name> <full-name>Administrator</full-name> <!-- other data tag elements for the admin user --> </user> </login> </system> </configuration> </rpc-reply>
Configuration Change Responses
Configuration change responses are
responses to requests that change the state or contents of the device
configuration. For commit operations, the Junos XML protocol server
returns the <commit-results>
response
tag, which encloses an explicit indicator of success or failure.
<rpc-reply xmlns:junos="URL"> <commit-results> <!-- tag elements for information about the commit --> </commit-results> </rpc-reply>
For other operations, instead of emitting an explicit
success indicator, the Junos XML protocol server indicates success
by returning an opening <rpc-reply>
tag
and closing </rpc-reply>
tag with no
child elements.
<rpc-reply xmlns:junos="URL"> </rpc-reply>
For more information, see Requesting Configuration Changes Using the Junos XML Protocol and Committing the Candidate Configuration Using the Junos XML Protocol. For a summary of the available configuration tag elements, see the Junos XML API Configuration Developer Reference.