Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Removed Java 8 info box

On this Page

Table of Contents
maxLevel2
excludeOlder Versions|Additional Resources|Related Links|Related Information

Java 8 throws an error if the maxOccurs value in your XSD file is greater than 5000. To overcome this error, set maxOccurs to unbounded. If you cannot modify the XSD, perform the following:
  • In the SnapLogic application, navigate to Manager > Project Spaces.

  • Click on your Project.

  • Click the Snaplexes tab and click on the Snaplex that you want to update.
    The Update Snaplex dialog box appears.

  • Under Global properties, click + to add a Key and Value.
    Image Removed

  • Enter jcc.jvm_options in Key.

  • Enter -Djdk.xml.maxOccurLimit=0 in Value.

  • Click Update

  • Restart the JCC.

    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. Specifies the incoming data to be validated against the provided XSD schema definition in Inbound Schema property.


    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. 

    Example: False

    Default value: False 

    Info
    Escape special characters

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

    • >
    • <
    • &
    • '
    • "

    Default value: Not selected.

    Note

    By default, this option is not selected to retain backward compatibility. But SnapLogic recommends you to select this option 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 schemfile.

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

    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
    titleMapping to XML Generator via XSD

    Mapping to XML Generator via XSD

    Let us use a JSON Generator to provide the input order data, such as defined below:

    Code Block
    [
        {
            "items" : [{
                "title": "iphone6",
                "quantity": 1,
                "price": 598.00
            },
            {
                "title": "note 4",
                "quantity": 1,
                "price": 599.00
            }
            ],
             "address":"some address",
            "city": "San Mateo",
            "orderId": "1234",
            "name": "Mr. Undecided"
        },
        {
            "items" : [{
                "title": "iphone6",
                "quantity": 1,
                "price": 598.00
            },
            {
                "title": "note 4",
                "quantity": 1,
                "price": 599.00
            },
            {
                "title": "lumina",
                "quantity": 1,
                "price": 0.99
            }
            ],
             "address":"some address",
            "city": "San Mateo",
            "orderId": "1234",
            "name": "Mr. Even more Undecided"
        }
    ]
     

    We then map the data using the Mapper Snap which has access to the XSD of the downstream XML Generator Snap of the previous example (now with an added input view).  


    Here we map the items to the item list on the target. Further we map the city, address, country and name to the shipTo object on the target and then finally we map the name against orderperson and orderId against @orderId on the target. The @ indicates we map against an XML attribute

    Let us see the output of the XML Snap.

    Here we see that each incoming order document was translated into an xml string. We include the original data from the input view, in case it is further needed downstream.
    The XML Generator Snap can validate the generated content if needed using the “Validate XML” property.


    Expand
    titleWriting the Generated Content to File

    Writing the Generated Content to File

    Sometimes one wants to write the generated XML to a file. For that use case we provide a DocumentToBinary Snap which can take the content and convert it to binary data object, which then can be written to a file, such as using a File Writer Snap.

     

    Above we map XML to the content field of the DocumentToBinary Snap, and set the Encode or Decode option on the DocumentToBinary Snap to NONE.


    This outputs then one binary document for each order. We can then write it to a directory. (Careful, here you’d want to use the APPEND option, since you potentially would be writing two files to the same directory or you can use an expression such as Date.now() to write individual files for each incoming binary data object).


    Expand
    titlePOSTing the Generated Content

    POSTing the Generated Content

    In the last example we will be POSTing the generated content to some REST endpoint using the REST POST Snap.


    In the screenshot below we are using the POST Snap which has the entity set as $xml. That will use the XML content that was generated by the upstream XML Generator Snap and POST it as a body to the endpoint.
    You might want to set the content-type and accept header as defined below.

     

    The POST will be executed for every document on the input view. There are a total of two documents, hence we will execute two post requests. 


    Expand
    titleValidating XML Data Using the Schema XPath and Validate XML Settings

    Validating XML Data Using the Schema XPath and Validate XML Settings

    This example demonstrates how to use the Schema XPath field to successfully validate XML data.

    Download the Sample Pipeline.

    In this Pipeline, custom XML data is provided using the Edit XML field in the XML Generator Snap, a snapshot of which is provided here. 

    The Inbound schema, Schema XPath, and the schema Root element, are specified in the Snap settings. See the screenshot below. In addition, the Validate XML check box is selected to indicate that the XML data must be validated against the schema.

    The file specified as the inbound schema, CustomersOrders_withXSD.xml, is not a regular schema file (.xsd) but an XML file being used as a schema file. The contents of this file appear as follows:

    In the above file, the root element of the schema is nested within the RootElm object. Therefore, the Schema XPath field value is specified as //RootElm/* to direct the XML Generator Snap to the schema object.   

    On validating the Pipeline, the Snap output appears as follows. Note the ContactName field. 

    If the ContactName field is removed from the custom XML specified in the XML editor and the Pipeline is re-validated, the Snap fails with the following error:

    Note that if the Validate XML check box is deselected, the Snap does not validate the data against the schema, and an output with the missing field is generated without errors:

    Similarly, if the Schema XPath value is not provided, the Snap is unable to locate the root element and fails with the following error: 

    This explains the scenarios in which you need to provide the schema XPath and how you can validate XML data using schema from within any XML or XSD file with the help of the Schema XPath and Validate XML properties.


    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.

    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.  


    Downloads

    Attachments
    patterns*.slp

    Excerpt Include
    Transform Snap Pack
    Transform Snap Pack
    nopaneltrue