Parsing of XML files in CDM
Summarize
Summary of Parsing of XML files in CDM
The CDM XML parser in ServiceNow facilitates the import and export of configuration data by converting XML files into JSON format and vice versa. This parsing capability enables clear identification and management of attribute key-value pairs within the Configuration Data Model (CDM) editor and list views.
Show less
Note: Starting with the Washington D.C. release, the DevOps Config feature is being deprecated and hidden on new instances but remains supported.
Key Features
- Converts XML element attributes into JSON key-value pairs by prefixing attribute keys with @.
- Uses the #text key to represent the enclosing text value of XML elements that contain both attributes and text.
- Supports importing existing configuration data from XML files, preserving attributes as JSON key-value pairs for easier differentiation in the CDM editor.
- Enables validation of imported CSV data with attributes for deployment within CDM.
- During export, converts JSON keys with @ prefixes back to XML attributes and handles enclosed text with #text keys to maintain original XML structure.
Practical Use for ServiceNow Customers
When importing XML configuration data into CDM, customers can expect attributes and element text to be accurately transformed into JSON format, simplifying editing and validation. Conversely, when exporting configuration data back to XML, maintaining proper attribute formatting and text content ensures consistency with original XML files.
To ensure correct export, customers should:
- Prefix attribute key names with @ in JSON to mark them as XML attributes.
- Include #text keys in JSON for elements that contain both attributes and text content.
Related Tasks
- Uploading configuration data into CDM.
- Adding nodes that contain configuration data to a new CDM application.
The CDM XML parser enables the parsing of attribute key-value pairs in XML files, so when you upload config data from an XML file into CDM, you can easily identify the attributes of each element in the CDM editor or list view.
- Uploading existing config data from an XML file, including the attributes of XML elements as appropriate key-value pairs in JSON.
- Differentiating attributes from the config data items easily in the CDM editor.
- Validating imported CSV data with attributes in CDM for deployment.
- Converting attribute key-value pairs in JSON format as XML element attributes in XML file.
Parsing of XML to JSON during import
- Adds the @ prefix to all key names corresponding to attributes of XML elements.
- Adds a #text key for the enclosing text value of XML elements that have both attributes and enclosing text.
- XML format
<app> <components> <paymentService type="B2C"> <provider region="EMEA">ABCPay</provider> <service>XYZPay</service> </paymentService> </components> <app>- JSON format
{ "app" : { "components" : { "paymentService" : { //key-value pair for XML elements with attributes "@type" : "B2C", // @ prefix for attribute "provider" : { "@region" : "EMEA", // @ prefix to key name for attribute "#text" : "ABCPay" // #text key name for enclosing text }, "service" : "XYZPay" //key-value pair for XML elements without attributes } } } }
Parsing of JSON to XML during export
- Add the @ prefix to all key names to make them parse as attributes of XML elements.
- Add keys named #text to CDIs that should be parsed as the enclosing text value of XML elements, when both attributes and enclosing text are present.