Directed Graphs: Escaping Xml
Table of Contents
Introduction
In XML certain characters have special meaning. Sometimes these characters may need to be used, but the intention is to use the literal character with no special meaning.
Escaped Characters
Character | Escaped Value |
---|---|
" | " |
' | ' |
< | < |
> | > |
& | & |
Example
<get-resource
plugin="com.att.sdnctl.sli.resource.sql.SqlResource"
resource="SQL"
key='SELECT
* FROM DATA_OBJECT_MAPPING WHERE data_object_type = "uCPE" AND
service_type = "UCPE" AND data_object_key2 =
$restapi-cust-result.customer-service-information.vnf-information.ucpe-host-name
AND data_object_key <> data_object_key2 AND data_object_key2_type =
"ucpe-Hostname"'
pfx="tmp.reference-data" >
Using this node would cause DGBuilder to throw an error when you click "Validate XML".
To fix this <> in the SQL query should be escaped. So the above node now becomes
<get-resource
plugin="com.att.sdnctl.sli.resource.sql.SqlResource"
resource="SQL"
key='SELECT
* FROM DATA_OBJECT_MAPPING WHERE data_object_type = "uCPE" AND
service_type = "UCPE" AND data_object_key2 =
$restapi-cust-result.customer-service-information.vnf-information.ucpe-host-name
AND data_object_key <> data_object_key2 AND data_object_key2_type =
"ucpe-Hostname"'
pfx="tmp.reference-data" >
You can refer to the chart above to perform similar manipulations.
Common Cases
SQL queries often contain invalid characters.
A developer might be tempted to write
<get-resource plugin="com.att.sdnctl.sli.resource.sql.SqlResource" resource="SQL"
key='select module, rpc, version, active ='Y' from SVC_LOGIC where module = $modname ;'
pfx="tmp">
This will be invalid because we have single quotes within single quotes. One solution is to escape them.
Another more legible solution is to use double quotes