This payload extracts the XML format content from the request and lets you extract the exact XML element value with it.
The fields for the XML payload are as seen in the following figure.
The properties for the XML payload are explained in the following table.
Properties | Description |
---|---|
XPath List | The XML element value to be extracted is specified in this field. Note: Ensure that you enter the XPath by following proper syntax for extracting the XML element value. If you enter incorrect syntax, then the service which has this XML payload definition in the rule fails to load and process the request. |
Advance XML Parser options* | Configure advanced parsing parameter options for the XML payload. This field accepts parsing options in the JSON format. The parsing options are of the Boolean data type. For example, the parsing parameter, remove_comments , accepts the values as true or false . |
* The Advance XML Parser options field provides the following parsing parameters that can be configured.
Options | Description | Default |
---|---|---|
remove_blank_text | Boolean value used to remove the whitespaces for indentation in the XML payload. | False |
remove_comments | Boolean value used to remove comments from the XML payload. In the XML format, comments are entered in the <!-- --> tag. | False |
remove_pis | Boolean value used to remove Processing Instructions (pi) from the XML payload. In the XML format, processing instructions are entered in the <? -- ?> tag. | False |
strip_cdata | Boolean value used to replace content in the cdata, Character data, or tag by normal text content. | True |
resolve_entities | Boolean value used to replace the entity value by their textual data value. | False |
no_network | Boolean value used to prevent network access while searching for external documents. | True |
ns_clean | Boolean value used to remove redundant namespace declarations. | False |
Consider the following example to understand the Advance XML Parser options available in the XML codec. In this example, a request is sent from a client to remove the whitespaces between the XML tags from a sample XML payload in the message body of the HTTP/REST request. The following Ruleset is created for this example.
Create an extract rule for the HTTP message payload using the default RuleSet template defined under the REST API service.
Consider the following sample XML payload in the HTTP message body.
<?xml version = "1.0" encoding = "ASCII" ?>
<class_list>
<!--Students grades are uploaded by months-->
<student>
<name>John Doe</name>
<grade>A</grade>
</student>
</class_list>
In the example, a lot of white spaces are used for indentation. The payload contain spaces, carriage returns, and line feeds between the <class_list>
, <student>
, and <name>
XML tags.
The extract rule for extracting the HTTP message body is as seen in the following figure.
Under the Extract rule, create another child rule to extract the XML payload from the HTTP Message.
In this child rule, provide /class_list/student/name
to parse the XML payload in the XPath List field and set the remove_blank_text parameter to true in the Advance XML Parser options field in the JSON format.
Under this extract rule, create another child rule to extract the sensitive data between the <name>
and <name>
tags. The fields for this child extract rule are as seen in the following figure.
Under the extract rule, create a transform rule to protect the sensitive data between the <name>
and the <name>
tags using Regex Replace with a pattern xxxxx
. The fields for the transform rule are as seen in the following figure.
Click Deploy or Deploy to Node Groups to apply the configuration changes.
When a request is sent to the configured URI, the DSG processes the request and the following response appears with the whitespaces removed from the XML payload. In addition, the sensitive data between the <name>
and the </name>
tags is protected.
<?xml version='1.0' encoding='ASCII'?>
<class_list><!--Students grades are uploaded by months--><student><name>xxxxx xxxxx</name><grade>A</grade></student></class_list>