XMLStreamingAPI - Scoped
-
- UpdatedJan 30, 2025
- 12 minutes to read
- Yokohama
- API reference
Builds a large streaming XML payload for use in a REST or SOAP request to send bulk data to a third-party API. You can also create the payload as an XML string for a non-streaming option.
sn_ih
namespace identifier. For example,
you can use this API to create an XML payload in the Workflow Studio
Script step and pass the returned value to the REST step to send the request to a
third-party service. For more information, see the Workflow Studio
Script
step.
There is no constructor for this class. Instead, you must call the build() method in the XMLStreamingBuilder class to return an XMLStreamingAPI object.
API call order
Generate XML payloads by first instantiating a builder object with XMLStreamingBuilder and then calling the methods in the XMLStreamingAPI class:
- 1. XMLStreamingBuilder: Creates a builder object
- Use these method in the following order to create a builder object:
- XMLStreamingBuilder(): Instantiates the XMLStreamingBuilder object.
- withAttachment(): Optional. Creates an XML document as an attachment and stores it in the Streaming Attachments [streaming_attachment] table. If you don't call this method, the API builds the payload as an XML string.
- expiresAt(): Optional. Sets a time when the attachment expires. False is the default. Must also call the withAttachment() method.
- build(): Returns an XMLStreamingAPI object.
- 2. XMLStreamingAPI: Builds the XML payload
- Use these methods in the following order to create the XML payload:
- startDocument(): Creates the top-level parent element in the XML document.
- Methods to generate child elements in the XML document, such as writeTextElement(), startElement(), and writeArray().
- Methods to generate attributes for an element, such as writeAttribute(), writeNamespace(), and writeDtd().
- endElement(): Closes an XML element.
- endDocument: Closes the top-level parent element.
- getXMLString() or getAttachmentId(): Returns the XML string or attachment ID that you created.
- close(): Closes the XMLStreamingAPI object.
Size limits
Payloads generated through this API cannot exceed these size limits:
- Attachments: 200 MB
- Strings: 5 MB
Example
The following example shows how to create an XML document and store it in the Streaming Attachments [streaming_attachment] table with a defined expiration date.
Alternatively, this example shows how to use the API in the Script step and create the payload as an XML string. You can use this option to create payloads under 5 MB.
Output:
XMLStreamingAPI - close()
Closes the XMLStreamingAPI object. You must call this method to close the stream after building your XML document.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
void |
Example
The following example shows how to create an XML document and store it in the Streaming Attachments [streaming_attachment] table with a defined expiration date.
XMLStreamingAPI - disablePrettyPrint()
Ends pretty print XML formatting.
Before calling this method, you must first call enablePrettyPrint() to add XML formatting to a section.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
The following example shows how to add pretty print formatting to the
address
element.
XMLStreamingAPI - enablePrettyPrint()
Adds pretty print formatting to an XML element or tree of elements.
Use the disablePrettyPrint() method to end the formatting.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
The following example shows how to add pretty print formatting to the
address
element.
XMLStreamingAPI - endDocument()
Ends the structure of your XML document.
After calling the startDocument() method and organizing your streaming XML document, call the endDocument() method at the end of your document's structure. You must use these two methods together to successfully build your streaming XML document's structure.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
The following example shows how to create an XML document containing elements about a user.
XMLStreamingAPI - endElement()
Adds a closing tag to an XML element.
- Use the startElement() method to add a starting tag.
- Use the endElement() method to add the closing tag.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
The following example shows how to build a parent element named address
and then write four child elements.
XMLStreamingAPI - getXMLString()
Returns the XML document as a string.
To return the XML document as a string, don't call the getAttachementId() method in the XMLStreamingBuilder class. For more information, see XMLStreamingBuilder - Scoped.
Name | Type | Description |
---|---|---|
None |
Type | Description |
---|---|
String | XML document created using the XMLStreamingAPI methods, as a string. |
Example
The following example shows how to create an XML document and then return it as a string.
Output:
XMLStreamingAPI - startDocument(String rootElement, Object namespaceDefinitionMap)
Begins building an XML document.
After calling the build() method, call the startDocument() method to start organizing your XML document. You must also call the endDocument method at the end of your document's structure.
Name | Type | Description |
---|---|---|
rootElement | String | Optional. Root element, or top-level parent element, for your XML document. |
namespaceDefinitionMap | Object | Optional. Map of keys and values for the namespaces and their associated values in a subsequent list of elements. For example: |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
The following example shows how to create an XML document containing elements with information about an employee.
XMLStreamingAPI - startElement(String name, Object namespaceMap, Object attributeMap, String prefix)
Adds a starting tag for an XML element.
- Use the startElement() method to add a starting tag.
- Use the endElement() method to add the closing tag.
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
The following example shows how to build a parent element named address and then write four child elements.
XMLStreamingAPI - writeArray(String elementName, Array data, String wrappingElement)
Adds a list of nested elements with predefined text to your streaming XML document.
After calling the startDocument() method, you can call the writeArray() method to add a block of nested elements to your streaming XML document.
Name | Type | Description |
---|---|---|
elementName | String | Name of the XML element associated with each string listed in the data array. |
data | Array | List of values to assign to each element nested inside wrappingElement. |
wrappingElement | String | Parent element containing each elementName. |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
The following example shows how to build a parent element named
officeLocations
, and then nest an array of five city
elements.
XMLStreamingAPI - writeAttribute(String name, String value)
Adds an attribute to an element in your XML document.
After calling the startDocument(), startElement(), or writeTextElement() method, you can call the writeAttribute() method to add an attribute to the associated XML element.
Name | Type | Description |
---|---|---|
name | String | Name of the XML element's attribute. |
value | String | Value for the XML element's attribute. |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
This example adds an attribute named idNumber to the employee element.
XMLStreamingAPI - writeAttributes(Object attributeMap)
Adds attributes to an element in your XML document.
After calling the startDocument(), startElement(), or writeTextElement() method, you can call the writeAttributes() method to add attributes to the associated XML element.
Name | Type | Description |
---|---|---|
attributeMap | Object | Map of keys and values containing attribute names and values to associate with the XML element. For example: |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
This example adds attributes named idNumber, officeLocation, and department to the employee element.
XMLStreamingAPI - writeCData(String data)
Adds CDATA to your XML document.
After calling the writeCDataElement() method, you can call the writeCData() method to add CDATA within the element.
Name | Type | Description |
---|---|---|
data | String | Value to include after the CDATA keyword in your CDATA element. |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
This example adds CDATA to the CDATA element
timeWorked
.
XMLStreamingAPI - writeCDataElement(String name, String data, Object prefix)
Adds a CDATA element to your XML document.
After calling the startDocument() method, you can call the writeCDataElement() method to add a CDATA element to your XML document.
Name | Type | Description |
---|---|---|
name | String | Name of the CDATA element. |
data | String | Optional. Type of data to parse the CDATA element as. |
prefix | Object | Optional. Map of child elements and values that the CDATA element includes. For example: writeNamespace(). | You must associate an XML element's prefix with a namespace using
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
This example uses a document type definition named address
to
define an internal document type definition for the XML document.
XMLStreamingAPI - writeCharacters(String text)
Adds text to your XML document.
Use the writeCharacters() method to insert string data to a section in your XML document.
Name | Type | Description |
---|---|---|
text | String | Text to add to a section of your XML document. |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
The following example shows how to add text values to elements in your XML document.
XMLStreamingAPI - writeComment(String comment)
Adds a comment to your XML document.
After calling the startDocument() method, you can call the writeComment() method to add a comment to your XML document.
Name | Type | Description |
---|---|---|
comment | String | Comment text to include. |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
The following example shows how to add a comment to an XML document.
XMLStreamingAPI - writeDtd(String dtd)
Adds a document type definition to your XML document.
After calling the startDocument() method, you can call the writeDtd() method to add a valid XML document type definition to your XML document.
Name | Type | Description |
---|---|---|
dtd | String | Name of a valid XML document type definition. |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
This example uses a document type definition named address to define an internal document type definition for the XML document.
XMLStreamingAPI - writeNamespace(String prefix, String namespaceURI)
Adds a namespace to an element in your XML document.
After calling the startDocument(), startElement(), or writeTextElement() method, you can call the writeNamespace() method to add a namespace to the associated XML element.
Name | Type | Description |
---|---|---|
prefix | String | Prefix for the XML namespace. |
namespaceURI | String | Optional. URI for the namespace. |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
The following example shows how to add a namespace and URI to the company
root element, and then assign the prefix to the nested companyName
element.
XMLStreamingAPI - writeNamespaces(Object namespaceMap)
Adds namespaces to the root element in your XML document.
After calling the startDocument() or startElement() method, you can call the writeNamespaces() method to declare namespaces for the associated XML element.
Name | Type | Description |
---|---|---|
namespaceMap | Object | Map of keys and values containing namespace prefixes and URIs to associate with the root element of the XML document. For example: |
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
This example adds two namespaces and URIs to the company root element, and then assigns the appropriate prefixes to the nested elements.
XMLStreamingAPI - writeTextElement(String name, String text, Object prefix)
Adds a single XML element to your XML document.
After calling the startDocument() method, you can call the writeTextElement() method to add a single XML element to your XML document's structure.
Name | Type | Description |
---|---|---|
name | String | Name of the XML element. |
text | String | Value for the XML element. |
prefix | Object | Optional. Map of prefixes and values associated with the XML element. For example: writeNamespace(). | You must associate an XML element's prefix with a namespace using
Type | Description |
---|---|
XMLStreamingAPI | Streaming XML object for constructing the payload. |
Example
The following example shows how to create an XML document containing three elements with information about an employee.
On this page
- API call order
- Size limits
- XMLStreamingAPI - close()
- XMLStreamingAPI - disablePrettyPrint()
- XMLStreamingAPI - enablePrettyPrint()
- XMLStreamingAPI - endDocument()
- XMLStreamingAPI - endElement()
- XMLStreamingAPI - getXMLString()
- XMLStreamingAPI - startDocument(String rootElement, Object namespaceDefinitionMap)
- XMLStreamingAPI - startElement(String name, Object namespaceMap, Object attributeMap,
String prefix)
- XMLStreamingAPI - writeArray(String elementName, Array data, String
wrappingElement)
- XMLStreamingAPI - writeAttribute(String name, String value)
- XMLStreamingAPI - writeAttributes(Object attributeMap)
- XMLStreamingAPI - writeCData(String data)
- XMLStreamingAPI - writeCDataElement(String name, String data, Object prefix)
- XMLStreamingAPI - writeCharacters(String text)
- XMLStreamingAPI - writeComment(String comment)
- XMLStreamingAPI - writeDtd(String dtd)
- XMLStreamingAPI - writeNamespace(String prefix, String namespaceURI)
- XMLStreamingAPI - writeNamespaces(Object namespaceMap)
- XMLStreamingAPI - writeTextElement(String name, String text, Object prefix)