On this Page
Table of Contents | ||||
---|---|---|---|---|
|
Snap type: | Read | |||||||
---|---|---|---|---|---|---|---|---|
Description: | This Snap generates a new XML document for the next Snap in the pipeline. The Snap will pass-through the input data if an input view is provided. The output of the Snap will provide an XML attribute in the document which provides the serialized XML content as a string.
| |||||||
Prerequisites: | [None] | |||||||
Support and limitations: | Works in Ultra Tasks. | |||||||
Account: | Accounts are not used with this Snap. | |||||||
Views: |
| |||||||
Settings | ||||||||
Label | Required. The name for the Snap. You can modify this to be more specific, especially if you have more than one of the same Snap in your pipeline. | |||||||
Inbound schema | XML schema definition of the incoming data. | |||||||
Schema XPath | The path for the schema object in the provided schema file, which must be used for validating the XML data. This is required if the schema object is nested within a wrapper object or within an object further in the schema file. See example Validating XML Data Using the Schema XPath for more information on using the Schema XPath field. | |||||||
XML root element | Root element for the XML generation. | |||||||
Validate XML | Required. Appears when you specify an XSD schema definition in the Inbound schema field. Select this checkbox to validate the incoming data against the specified XSD schema definition.
Default Value: Deselected | |||||||
Escape special characters | Select this checkbox to escape XML special characters in XML template variable values when you insert the values into the Apache Velocity template. For example, the Snap replaces < with &It;. The special characters that the Snap escapes are:
XML Generator normalizes all attributes to use double quotes for the delimiters, even if the source content uses single quotes. Therefore, if there are double quotes that appear inside the attributes, then they have to be escaped. Learn more: 1439386. Default value: Not selected
| |||||||
Default value for substitution | This value will be used for substitution for the leaf elements which are not objects and/or not enclosed in an array. If nothing is specified and Use default value for substitution is selected, an empty string will be used for substitution. | |||||||
Use default value for substitution | If you select this check box, the value provided for the Default value for substitution is used for substitution if the elements do not exist in the incoming documents. Otherwise, the elements for which the incoming documents do not have any values will be deleted from the XML. | |||||||
Namespace Context | Namespace context for schema element. | |||||||
Prefix | Prefix of schema element in the provided schema file. | |||||||
Namespace URI | Namespace of schema element in the provided schema file. | |||||||
Edit XML | Required. This property lets you edit the XML contents. The elements to be generated in the output must be specified in the XML template. If your output does not display the required elements, click Edit XML and specify the applicable elements in the Generate Template tab. You can use the /wiki/spaces/AP/pages/1438085 template Apache Velocity template to pass dynamic values from upstream Snaps.
| |||||||
Snap Execution | Select one of the three modes in which the Snap executes. Available options are:
|
Handling Special Characters
...
He said "OK" | attributeName="He said "OK"" | The double quotes must be escaped. |
He said "OK" | attributeName='He said "OK"' | The double quotes need not be escaped as they are contained within a single-quoted attribute. |
She said "You're right" | attributeName="She said "You're right"" | The ' (apostrophe) in You’re need not be escaped as it is contained within double quotes. |
She said "You're right" | attributeName='She said "You're right"' | The double quotes need not be escaped as they are contained within a single-quoted attribute. However, you must escape the apostrophe in You’re. |
She said "You're right" | attributeName="She said "You're right"" | To escape all the data. |
Smith&Sons | attributeName="Smith&Sons" | The & must always be escaped within attribute data. |
a>b a<b | attributeName="a>b" attributeName="a<b" | It is good practice to escape > or < characters, though not mandatory if they are used in an attribute. |
if (age < 5) if (age > 5) if (age > 3 && age < 8) | <MyElement>if (age < 5)</MyElement> <MyElement>if (age > 5)</MyElement> <MyElement>if (age > 3 && age < 8)</MyElement> | It is good practice to escape >, <, or & characters if they are used within an element though not mandatory. |
She said "You're right" | <MyElement>She said "You're right"</MyElement> | The single and double quotes need not be escaped if they are within an Element |
Troubleshooting
...
XML Formatter and XML Generator Output Differs for the Same XSD File Input
The XML Formatter and XML Generator Snaps work differently for an XSD file as the input document. To generate the same output from both the Snaps, append the following to the required schema in the Target path property of the preceding Mapper Snap:
- XML Formatter:
.$
- XML Generator:
.value
Examples
...
Expand | ||
---|---|---|
| ||
XML Generation via XSDThe first example depicts a simple pipeline to generate order data XML directly with the XML Generator Snap.
We provide the sample XSD as defined below:
We then suggest the XML root element, which returns {}shiporder. Now we could replace the variables with our own values to generate the XML on the output view or move on to the next example. |
...
Expand | ||
---|---|---|
| ||
Custom XML Output Generation using Inbound Schema and Root ElementThis example illustrates the corrected behavior of the XML Generator Snap as of Patch transform8760, whereby the Snap does not ignore any custom XML data that is provided through its XML editor. Download the Sample Pipeline. Scenario 1: When used with upstream Snaps The sample Pipeline provided here generates XML for an Add operation. The XML output should contain two integer values: intA and intB.
In the Customized XML Snap, custom XML data is provided using the Edit XML field in the Snap Settings as follows:
The Generated XML Snap contains the XML that is generated through the Generate Template button in the XML editor: In this case, the values of Both Snaps are fed an input document that specifies Old behavior: Current behavior: The output of the Generated XML Snap is based on upstream data: Scenario 2: When used as a standalone Snap The sample Pipeline provided below generates XML for an Add operation. Custom XML is provided using the Edit XML field, as follows: Old behavior: Pipeline execution would result in a Current behavior: Pipeline execution is successful and custom XML output is generated: This example illustrates how you can generate custom XML output through the XML Generator Snap. |
...