Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

On this Page

...

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.

  • Expected upstream Snaps: A Mapper Snap which maps into the JSON schema provided by the XML Generator Snap. The provided JSON schema is derived from the XSD that can be provided for the XML Generator Snap.
  • Expected downstream Snaps: The Snap will output one document for every input document, hence and document processing Snap can be used downstream. 
  • Expected input: Document that conforms to variables needed for the variable substitutions of the XML template.
  • Expected output: Document which provides the results of the XML template substitution. Every input document (if an input view is provided) will result in a one output document which provides the result of the XML template substitution under the XML attribute of the document.


Prerequisites:

[None]


Support and limitations:Works in Ultra Task Pipelines.
Account: 

Accounts are not used with this Snap.


Views:


InputThis Snap has at most one document input view.
OutputThis Snap has exactly one document output view.
ErrorThis Snap has at most one document error view and produces zero or more documents in the view.


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.

Note

If you enter an Inbound schema, then you must select Validate XML and Match data types properties to derive the output as per the defined schema. 

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: HandlingSpecialCharacters1439386.

Default value: Not selected

Note

We recommend that you select this checkbox unless your variable values contain XML Markup or the contents are already escaped.


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 substitutionIf 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 Apache Velocity/wiki/spaces/AP/pages/1438085 template to pass dynamic values from upstream Snaps.

Note

Elements specified in the schema document in the Inbound schema field do not affect the output.


Multiexcerpt include macro
nameSnap Execution
pageAnaplan Read

Multiexcerpt include macro
nameSnap_Execution_Introduced
pageAnaplan Read

...

Example

Attribute/Element in XML

Description

He said "OK"

attributeName="He said &quot;OK&quot;"

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 &quot;You're right&quot;"

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&apos;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 &quot;You&apos;re right&quot;"

To escape all the data.

Smith&Sons

attributeName="Smith&amp;Sons"

The & must always be escaped within attribute data.

a>b

a<b

attributeName="a&gt;b"

attributeName="a&lt;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 &lt; 5)</MyElement>

<MyElement>if (age &gt; 5)</MyElement>

<MyElement>if (age &gt; 3 &amp;&amp; age &lt; 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
titleXML Generation via XSD

XML Generation via XSD

The 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:

Code Block
<?xml version="1.0" encoding="UTF-8" ?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="shiporder">
  <xs:complexType>
 <xs:sequence>
   <xs:element name="orderperson" type="xs:string"/>
   <xs:element name="shipto">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="name" type="xs:string"/>
         <xs:element name="address" type="xs:string"/>
         <xs:element name="city" type="xs:string"/>
         <xs:element name="country" type="xs:string"/>
       </xs:sequence>
     </xs:complexType>
   </xs:element>
   <xs:element name="item" maxOccurs="unbounded">
     <xs:complexType>
       <xs:sequence>
         <xs:element name="title" type="xs:string"/>
         <xs:element name="note" type="xs:string" minOccurs="0"/>
         <xs:element name="quantity" type="xs:positiveInteger"/>
         <xs:element name="price" type="xs:decimal"/>
       </xs:sequence>
     </xs:complexType>
   </xs:element>
 </xs:sequence>
 <xs:attribute name="orderid" type="xs:string" use="required"/>
  </xs:complexType>
</xs:element>
</xs:schema>


Originated from: http://www.w3schools.com/schema/schema_example.asp

 

We then suggest the XML root element, which returns {}shiporder.
Finally we click on Edit XML, which will automatically trigger the XML template generation based off the XSD, see below.

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. 
*The execution of the Snap above will create an XML attribute on the output view which provides the serialized XML content as a string. 

...

Expand
titleCustom XML Output Generation using Inbound Schema and Root Element 

Custom XML Output Generation using Inbound Schema and Root Element 

This 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.



Using two XML Generator Snaps: Customized XML and Generated XML, the Pipeline demonstrates the differing output when custom XML is provided vs when the output is generated using upstream data. Both Snaps are provided the same schema info.

In the Customized XML Snap, custom XML data is provided using the Edit XML field in the Snap Settings as follows:



Here, the values of intA and intB are 0 and 1 respectively.

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 intA and intB are dynamically assigned when the Snap executes.

Both Snaps are fed an input document that specifies intA=2, and intB=3.

Old behavior:
The Customized XML Snap had the same output as the Generated XML Snap and ignored the custom XML data in the editor:

Current behavior:
The two Snaps have different outputs. The output of the Customized XML Snap is based on the XML provided by the user:

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.

Image Modified

Custom XML is provided using the Edit XML field, as follows: 

Old behavior:

Pipeline execution would result in a Premature end of file error: 

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.  

...