跳至主要内容
Adaptive Planning
上次更新时间 :2024-09-20
ai.xml

ai.xml

Functions

Method
Parameters
Returns
Description
createFromUrl(url, method, body, headers, callbacks)
available as of 2018.3
url: String Valid URL
method: String Valid HTTP method
body: String Request body
headers: String HTTP Header
callbacks: Object A function
ai.xml.sax
Creates an XML SAX parser object that can parse an XML stream.
createFromUrlWithAuthorisation(url, method, body, headers, callbacks)
available as of 2018.3
url: String Valid URL
method: String Valid HTTP method
body: String Request body
headers: String HTTP Header
callbacks: Object A function
ai.xml.sax
Creates an XML SAX parser object that can parse an XML stream with authorisation using OAuth.
createParser()
ai.xml.parser
Creates a XML parser object that can parse XML strings.
createDocument()
ai.xml.document
Creates a XML document.
createDocType( xmlStr )
  • xmlStr : String Valid DOCTYPE XML string
ai.xml.docType
Create a doctype object that is added to a XML document to define its doctype.
createElement( name )
  • name : String Name of the XML element
ai.xml.element
Create a XML element, which is the basic building block of a XML document, that can be added to an XMLdocument.
createAttribute( name, value )
  • name : String Name of the attribute
  • value : String Value of the attribute
ai.xml.attribute
Creates an attribute object that can be added to a XML element.
Examples
// Construct the sample XML request below /* <request> <control> <senderid>adaptiveplanning</senderid> <password>Bts9DrRkeZ</password> <controlid>SomeRandomThingToMatchToResponse</controlid> <dtdversion>3.0</dtdversion> </control> </request> */ // create XML document var doc = ai.xml.createDocument(); // create root element var requestEl = ai.xml.createElement('request'); // create control element var controlEl = ai.xml.createElement('control'); //create senderid element var senderIdEl = ai.xml.createElement('senderid'); senderIdEl.setText('adaptiveplanning'); //add <senderid> to <control> element controlEl.addChildElement(senderIdEl); //create password element var controlPasswordEl = ai.xml.createElement('password'); controlPasswordEl.setText('Bts9DrRkeZ'); //add <password> to <control> element controlEl.addChildElement(controlPasswordEl); //create controlid element var controlIdEl = ai.xml.createElement('controlid'); controlIdEl.setText('SomeRandomThingToMatchToResponse'); //add <controlid> to <control> element controlEl.addChildElement(controlIdEl); //create dtdversion element var dtdEl = ai.xml.createElement('dtdversion'); dtdEl.setText('3.0'); //add <dtdversion> to <control> element controlEl.addChildElement(dtdEl); //add <control> element to the main <request> element requestEl.addChildElement(controlEl); //set <request> as the doc's root element doc.setRootElement(requestEl);

ai.xml.sax

Method
Parameters
Returns
Description
createFromText()
XML:string
Encoding: UTF8
Callbacks: An object with functions
ai.xml.sax
Creates an XML SAX parser object that can parse XML text.
Limited to 2.5 million characters.
createFromUrl()
url: String Valid URL
method: String Valid HTTP method
body: String Request body
headers: String HTTP Header
callbacks: An object with functions
ai.xml.sax
Creates an XML SAX parser object that can parse an XML stream.
createFromUrlWithAuthorisation()
url: String Valid URL
method: String Valid HTTP method
body: String Request body
headers: String HTTP Header
callbacks: An object with functions
ai.xml.sax
Creates an XML SAX parser object that can parse an XML stream with authorisation using OAuth.
The
ai.xml.sax
examples below use
callbacks
. A callback is a function that executes after another function finishes executing. One of the benefits of using callbacks with ai.xml.sax parsers is that you can catch errors and present those errors in the logs of a CCDS run for easier troubleshooting.
ai.xml.sax.createFromText example
var data = { books: [], currentTag: '' }; function createSaxParser(callbacks) { var xml = '<BookStore><book category="Cooking"><title lang="en">Everyday Italian</title><author>Giada De Laurentiis</author><year>2005</year><price>$30.00</price></book><book category="Children"><title lang="en">Harry Potter</title><author>Norwegian: . French: </author><year>2015</year> <price>$50.00</price></book><book category="Sports"><title lang="en">Sports for Health</title><author>&#352;umbera</author><year>2016</year><price>$330.00</price></book> </BookStore>'; try { return ai.xml.sax.createFromText(xml, "UTF8", callbacks); } catch(exception) { ai.log.logError('Unable to setup sax parser', '' + exception); throw exception; } } function testConnection(context) { var parser = null; var callbacks = {}; var matched = false; callbacks.onOpenTag = function (tag) { if(tag.name === 'book') { matched = true; parser.stop(); } }; parser = createSaxParser(callbacks); parser.readToEnd(); return matched; } function importStructure(context) { var builder = context.getStructureBuilder(); var table = builder.addTable('MyNewTableFromText'); table.setDisplayName('MyNewTableFromText'); addColumn(table, 'book', 1, 'string', 100); addColumn(table, 'title', 2, 'string', 500); addColumn(table, 'author', 3, 'string', 100); addColumn(table, 'year', 4, 'string', 200); addColumn(table, 'price', 5, 'string', 1000) } function importData(context) { var rowset = context.getRowset(); rowset.setSmartParsingEnabled(true); var parser = null; var callbacks = {}; callbacks.onOpenTag = function (tag) { data.currentTag = tag.name; if(tag.name === 'book') { var book = { category: tag.attributes['category'] }; data.books.push(book); } }; callbacks.onText = function (text) { var current = data.books.length > 0 ? data.books[data.books.length-1] : null; if(data.currentTag === 'title') { current.title = text; } if(data.currentTag === 'author') { current.author = text; } if(data.currentTag === 'year') { current.year = text; } if(data.currentTag === 'price') { current.price = text; } }; callbacks.onCloseTag = function (tagname) { if(tagname === 'book') { var saving = data.books.pop(); save(rowset, saving); } }; parser = createSaxParser(callbacks); parser.readToEnd(); } function addColumn(table, columnName, order, type, length) { var newCol = table.addColumn(columnName); newCol.setDisplayName(columnName); newCol.setDisplayOrder(order); newCol.setIncludeByDefault(true); switch (type) { case 'string': newCol.setTextColumnType(length); newCol.setRemoteColumnType('string'); break; case 'datetime': newCol.setDateTimeColumnType(); newCol.setRemoteColumnType('datetime'); break; case 'float': newCol.setFloatColumnType(); newCol.setRemoteColumnType('float'); break; default: newCol.setTextColumnType(100); newCol.setRemoteColumnType('string'); } } var save = function (rowset, book) { var cells = []; cells.push(book.category); cells.push(book.title); cells.push(book.author); cells.push(book.year); cells.push(book.price); rowset.addRow(cells); };
ai.xml.sax.createFromUrl example
var data = { entires: [], currentTag: '' }; function createSaxParser(callbacks) { var url = 'https://earthquake.usgs.gov/earthquakes/feed/v1.0/summary/all_hour.atom'; var method = 'GET'; var body = ``; var headers = {}; try { return ai.xml.sax.createFromUrl(url, method, body, headers, callbacks); } catch (exception) { ai.log.logError('Unable to setup sax parser', '' + exception); throw exception; } } function testConnection(context) { var parser = null; var callbacks = {}; var matched = false; callbacks.onOpenTag = function (tag) { if (tag.name === 'entry') { matched = true; parser.stop(); } }; parser = createSaxParser(callbacks); parser.readToEnd(); return matched; } function importStructure(context) { var builder = context.getStructureBuilder(); var table = builder.addTable('StandardLoaderData'); table.setDisplayName('StandardLoaderData'); addColumn(table, 'id', 0, 'string', 100); addColumn(table, 'title', 1, 'string', 500); addColumn(table, 'updated', 2, 'string', 100); addColumn(table, 'link', 3, 'string', 200); addColumn(table, 'summary', 4, 'string', 1000); addColumn(table, 'georss:point', 5, 'string', 200); addColumn(table, 'georss:elev', 6, 'string', 200); } function importData(context) { var rowset = context.getRowset(); rowset.setSmartParsingEnabled(true); var parser = null; var callbacks = {}; callbacks.onOpenTag = function (tag) { data.currentTag = tag.name; if (tag.name == 'entry') { var entry = {}; data.entires.push(entry); return; } if (tag.name == 'link') { if (tag.attributes) { var current = data.entires.length > 0 ? data.entires[data.entires.length-1] : null; if(current !== null) { current.link = tag.attributes["href"]; } } } }; callbacks.onText = function (text) { var current = data.entires.length > 0 ? data.entires[data.entires.length-1] : null; if(current === null) { return; } switch (data.currentTag) { case "id": case "title": case "updated": case "summary": case "georss:point": case "georss:elev": current[data.currentTag] = text; break; } }; callbacks.onCloseTag = function (tagname) { if (tagname == 'entry') { var saving = data.entires.pop(); save(rowset, saving); } }; callbacks.onCData = function (data) { if (data.length === 0) return; if (data.currentTag == 'summary') { var current = data.entires.length > 0 ? data.entires[data.entires.length-1] : null; current.summary = data; } }; parser = createSaxParser(callbacks); parser.readToEnd(); } function addColumn(table, columnName, order, type, length) { var newCol = table.addColumn(columnName); newCol.setDisplayName(columnName); newCol.setDisplayOrder(order); newCol.setIncludeByDefault(true); switch (type) { case 'string': newCol.setTextColumnType(length); newCol.setRemoteColumnType('string'); break; case 'datetime': newCol.setDateTimeColumnType(); newCol.setRemoteColumnType('datetime'); break; case 'float': newCol.setFloatColumnType(); newCol.setRemoteColumnType('float'); break; default: newCol.setTextColumnType(100); newCol.setRemoteColumnType('string'); } } var save = function (rowset, entry) { var cells = []; cells.push(entry.id || ''); cells.push(entry.title || ''); cells.push(entry.updated || ''); cells.push(entry.link || ''); cells.push(entry.summary || ''); cells.push(entry['georss:point'] || ''); cells.push(entry['georss:elev'] || ''); rowset.addRow(cells); };

ai.xml.parser

Method
Parameters
Returns
Description
parse( xmlStr )
  • xmlStr Valid XML document string
ai.xml.document
Parses a valid XML document string into a XML document.
Example for parse
var xmlString = '<request><control><senderid>adaptiveplanning</senderid><password>Bts9DrRkeZ</password><controlid>SomeRandomThingToMatchToResponse</controlid><dtdversion>3.0</dtdversion></control><operation><authentication><login><userid>Julia</userid><companyid>companyplanningDEV</companyid><password>GhY93tYi</password></login></authentication></operation></request>'; var parser = ai.xml.createParser(); var xmlDoc = parser.parse(xmlString); /* Output: <request> <control> <senderid>adaptiveplanning</senderid> <password>Bts9DrRkeZ</password> <controlid>SomeRandomThingToMatchToResponse</controlid> <dtdversion>3.0</dtdversion> </control> <operation> <authentication> <login> <userid>Julia</userid> <companyid>companyplanningDEV</companyid> <password>GhY93tYi</password> </login> </authentication> </operation> </request> */

ai.xml.document

Method
Parameters
Returns
Description
clone()
ai.xml.document
Returns a clone of this document.
getDOCTYPE()
ai.xml.docType
Gets the document DOCTYPE.
getRootElement()
ai.xml.element
Gets the root element in the document.
setDOCTYPE( docType )
  • docType : ai.xml.docType DOCTYPE to set the document to
Sets the document DOCTYPE.
setRootElement( element )
  • element : ai.xml.element Element to be the root element of the document.
Sets the document root element.
toString()
Provides a formatted string representation of the XML document.

ai.xml.docType

Method
Parameters
Returns
Description
toString()
String
Provides a string representation of this document type declaration.
Example
var doc = ai.xml.createDocument(); var docType = ai.xml.createDocType('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'); //set doc type doc.setDOCTYPE(docType); //get doc type var getdoctype=doc.getDOCTYPE(); var rootEl = ai.xml.createElement('Books'); //set root element doc.setRootElement(rootEl); //sample clone var cloned_doc=doc.clone(); //get root element var docRoot=doc.getRootElement(); //convert the xml result to a string for logging ai.log.logInfo(doc.toString()) /*Output: Cloned data: <Books /> Doc type is<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Root element is <Books /> */

ai.xml.element

Method
Parameters
Returns
Description
addChildElement( element )
  • element : ai.xml.element Element to add
Adds a child element.
clone()
ai.xml.element
Returns a clone of this element.
getAttribute( name )
name : String Name of the attribute
ai.xml.attribute
Gets the attribute of the given name.
getAttributeAt( index )
index : Integer Index of attribute
ai.xml.attribute
Gets the attribute at the given index of the attributes array for this element.
getAttributes()
Array<ai.xml.attribute>
Gets the attributes of this element.
getAttributeValue( name )
  • name : String Name of the attribute
String
Gets the value of the attribute of the given name.
getChildElement( name )
  • name : String Name of the element
ai.xml.element
Gets the first child element having the specified given name.
getChildElementAt( index )
  • index : Integer Index of the element
ai.xml.element
Gets a child element at the given index within the child elements.
getChildElements()
Array<ai.xml.elements>
Gets the array of all child elements for this element.
getChildElements( name )
  • name : String Name of the elements
Array<ai.xml.element>
Gets the array of child elements for this element with the given name.
getCommentText()
String
Gets the comment text.
getName()
String
Gets the qualified name of this element.
getText()
String
Gets the text of this element or CDATA.
hasContents()
Boolean
Indicates whether or not this element has child contents: Text, CDATA or child elements.
removeAllAttributes()
Removes all attributes from this element.
removeAttribute( name )
  • name : String Name of the attribute
Removes the attribute of the given name in the element attributes array, and recompresses the array.
removeChildElement( name )
  • name : String Name of the element
Removes the first child element having the specified name.
removeChildElementAt( index )
  • index : Integer Index of the element
Removes a child element at the given index within the child elements.
removeChildElements()
Integer
Removes all child elements from this element and returns count of elements removed.
removeChildElements( name )
  • name : String Name of the elements
Integer
Removes all child elements of the given element name from this element and returns count of elements removed.
removeComments()
Removes all comments attached directly to this element.
removeText()
Removes all text (including CDATA sections) attached directly to this element.
setAttribute( attribute)
  • attribute : ai.xml.attribute The attribute object to add
Adds an attribute to this element.
setAttribute(name, value )
  • name : String Name of the attribute
  • value : String Value of the attribute
Sets the value of the attribute of the given name, for this element.
setCDATAText( text )
  • text : String CDATA text
Removes all existing content (except comments) from this element, including child elements, and then sets CDATA section text for this element.
setCommentText( text )
  • text : String Comment text
Removes all comments attached directly to this element, and then adds a new comment with the given text.
setName( name )
  • name : String Name of the element
Sets the name of this element.
setText( text )
  • text : String Text value of the element
Removes all existing content (except comments) from this element, including child elements, and then sets the element text.
toString()
Provides a formatted string representation of this element.
Examples
Example for createDocument(), createElement(name), addChildElement(name), clone(), setText(), setCommentText(text), getCommentText()
// create XML document var doc = ai.xml.createDocument(); // create root element var requestEl = ai.xml.createElement('request'); // create an element '<control>' var controlEl = ai.xml.createElement('control'); //create a username or id element '<senderid>' var senderIdEl = ai.xml.createElement('senderid'); //set text for the senderid element 'adaptive planning' senderIdEl.setText('adaptiveplanning'); //add <senderid> to <control> element controlEl.addChildElement(senderIdEl); //create a <password> element var passwordEl = ai.xml.createElement('password'); //set text for the password element 'pwd' passwordEl.setText('pwd'); //add <password> to <control> element controlEl.addChildElement(passwordEl); //add <control> element to the root requestEl.addChildElement(controlEl); //clone the sender id element cloneEl=senderIdEl.clone(); //add clone() element to the root element requestEl.addChildElement(cloneEl); //setCommentText requestEl.setCommentText("The above element is cloned"); //get comment text ai.log.logInfo(getCommentText()); //Log Output: The above element is cloned //set document's root doc.setRootElement(requestEl); /* Output: <request> <control> <senderid>adaptiveplanning</senderid> </control> <senderid>adaptiveplanning</senderid> <!-- The above element is cloned--> </request> */
Example for getChildElement(), getChildElementAt(), getChildElements and getChildElements( name )
// create XML document var doc = ai.xml.createDocument(); // create root element var requestEl = ai.xml.createElement('request'); // create an element '<control>' var controlEl = ai.xml.createElement('control'); //create a username or id element '<senderid>' var senderIdEl = ai.xml.createElement('senderid'); //set text for the senderid element 'adaptive planning' senderIdEl.setText('Sender id 1'); //add <senderid> to <control> element controlEl.addChildElement(senderIdEl); //create another sender id element '<senderid>' var senderIdEl2 = ai.xml.createElement('senderid'); //set text for the senderid element 'adaptive planning' senderIdEl2.setText('Sender id 2'); //add <senderid> to <control> element controlEl.addChildElement(senderIdEl2); //create a <password> element var passwordEl = ai.xml.createElement('password'); //set text for the password element 'pwd' passwordEl.setText('pwd'); //add <password> to <control> element controlEl.addChildElement(passwordEl); //add <control> element to the root requestEl.addChildElement(controlEl); //set document's root doc.setRootElement(requestEl); //getChildElement(name) var firstChildElement="First Child element of <control> is "+requestEl.getChildElement( "senderid" ).toString(); //Output: First Child element of <control> is <senderid>Sender id 1</senderid> //getChildElementAt(index) var elementIndex="Element at index 0 is"+requestEl.getChildElementAt( 0 ).toString(); /* Output: Element at index 0 is <control><senderid>Sender id 1</senderid><senderid>Sender id 2</senderid><password>pwd</password></control> */ //getChildElements() var specificChildElements="Child elements for the control element:"+controlEl.getChildElements().toString(); //Output: <senderid>Sender id 1</senderid><senderid>Sender id 2</senderid><password>pwd</password> //getChildElements(name) var childElementsControl="All child elements of control element with <senderid>: "+controlEl.getChildElements("senderid" ).toString(); //Output:All child elements of control element with <senderid>:<senderid>Sender id 1</senderid>,<senderid>Sender id 2</senderid>
Examples for hasContents(), removeChildElement( name ), removeChildElementAt(index), removeChildElements() and removeChildElements( name )
// create XML document var doc = ai.xml.createDocument(); // create root element var requestEl = ai.xml.createElement('request'); // create an element '<control>' var controlEl = ai.xml.createElement('control'); //create a username or id element '<senderid>' var senderIdEl = ai.xml.createElement('senderid'); //set text for the senderid element 'adaptive planning' senderIdEl.setText('Sender id 1'); //getText() ai.log.logInfo(senderIdEl.getText()); //Sender id 1 //add <senderid> to <control> element controlEl.addChildElement(senderIdEl); //create another sender id element '<senderid>' var senderIdEl2 = ai.xml.createElement('senderid'); //set text for the senderid element 'adaptive planning' senderIdEl2.setText('Sender id 2'); //add <senderid> to <control> element controlEl.addChildElement(senderIdEl2); //create a <password> element var passwordEl = ai.xml.createElement('password'); //set text for the password element 'pwd' passwordEl.setText('pwd'); //add <password> to <control> element controlEl.addChildElement(passwordEl); //add <control> element to the root requestEl.addChildElement(controlEl); //set document's root doc.setRootElement(requestEl); //removeChildElement of <control> element - First child element removal var removeFirstChildElement=controlEl.removeChildElement( "senderid" ); /*Output: |Inital XML | After removal of the child element <request> <request> <control> <control> <senderid>Sender id 1</senderid> <senderid>Sender id 2</senderid> <senderid>Sender id 2</senderid> <password>pwd</password> <password>pwd</password> </control> <control/> </request> <request/> */ //removeChildElementAt index 0 var removeIndexChildElement=requestEl.removeChildElementAt(0); /*Output: |Initial XML | After removing the child element at index 0 <request> <request><request/> <control> <senderid>Sender id 1</senderid> <senderid>Sender id 2</senderid> <password>pwd</password> <control/> <request/> */ //removeChildElements() var removeAllChildElements= controlEl.removeChildElements(); /*Output: |Initial XML | After removing the child element at index 0 <request> <request><control/><request/> <control> <senderid>Sender id 1</senderid> <senderid>Sender id 2</senderid> <password>pwd</password> <control/> <request/> */ //removeChildElements( name ) and hasContents() if(controlEl.hasContents()){ var removeSpecificElement=controlEl.removeChildElement( "senderid" ); } /*Output: |Inital XML | After removal of the child element <request> <request> <control> <control> <senderid>Sender id 1</senderid> <password>pwd</password> <senderid>Sender id 2</senderid> </control> <password>pwd</password> </request> <control/> <request/> */

ai.xml.attribute

Method
Parameters
Returns
Description
clone()
ai.xml.attribute
Returns a clone of this attribute.
getName()
String
Gets the name of the attribute.
getValue()
String
Gets the value of the attribute.
setName( name )
  • name : String Name of the attribute
Sets the name of the attribute.
setValue( value )
  • value : String Value of the attribute
Sets the value of the attribute.
toString()
Returns a string representation of this attribute.
Example
var tablesElement = ai.xml.createElement('Tables'); var table1Element = ai.xml.createElement('Table'); var row1=ai.xml.createElement('row'); var row2=ai.xml.createElement('row'); //Create a new arribute var attribute1 = ai.xml.createAttribute('remoteId', '248'); //Add the attribute to <table> element using setAttribute(ai.xml.attribute) table1Element.setAttribute(attribute1); //Or set the name and value of the attribute for the <row> elements using setAttribute(name,value) row1.setAttribute('age','50'); row1.setAttribute('color','white'); row2.setAttribute('age','35'); row2.setAttribute('color','blue'); //Set text for the <table> element table1Element.setText('Sample table'); //Add <table> as the child of <tables> element tablesElement.addChildElement(table1Element); table1Element.addChildElement(row1); table1Element.addChildElement(row2); /*Ouput <Tables> <Table remoteId="248"> Sample table <row age="50" /> <row age="35" /> </Table> </Tables> */ //Clone() attributes var cloned = row1.clone(); cloned.setName('cloned_row'); table1Element.addChildElement(cloned); /*Ouput <Tables> <Table remoteId="248"> Sample table <row age="50" /> <row age="35" /> <cloned_row age="50"> </Table> </Tables> */ //getAttribute( name ) ai.log.logInfo(table1Element.getAttribute("remoteid")); //Output:remoteId="248" //getAttributeAt( index ) ai.log.logInfo(row1.getAttributeAt(0).toString()); //Output: age=50 //getAttributes() ai.log.logInfo(row1.getAttributes().toString()); //Output: age="50",color="white" //getAttributeValue( name ) ai.log.logInfo(row2.getAttributeValue('color').toString()); //Output: blue //removeAttribute( name ) var removeRow1Attribute=row1.removeAttribute('age'); /*Output: |Inital XML | After removing the attribute 'age' for row1 <Tables> <Tables> <Table remoteId="248">Sample table <Table remoteId="248">Sample table <row age="50" color="white" /> <row color="white" /> <row age ="35" color="blue" /> <row age ="35" color="blue" /> <Table/> <Table/> <Tables/> <Tables/> */ //removeAllAttributes() var removeRow1Attributes=row1.removeAllAttributes(); /*Output: |Inital XML | After removing the attribute 'age' for row1 <Tables> <Tables> <Table remoteId="248">Sample table <Table remoteId="248">Sample table <row age="50" color="white" /> <row/> <row age ="35" color="blue" /> <row age ="35" color="blue" /> <Table/> <Table/> <Tables/> <Tables/> */

View XML Output logs with AWS S3

You must parse your sample XML before logging the results with the ai.log methods. To view raw XML samples, convert the file to a string with
toString()
function and view the file in your AWS S3 bucket.
Use the example below to connect to your AWS S3 instance for creating and viewing your XML results. You will need the bucket name, key, access key, secret key and region values. For more information and example codes, see ai.awss3
Example
function testConnection(context) { var bucketName = 'xxx'; var key = 'newfile.xml'; var awsAccessKey = 'xxx'; var awsSecretKey = 'xxx'; var region = 'xxx' var doc = ai.xml.createDocument(); var docType = ai.xml.createDocType('<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">'); //set doc type doc.setDOCTYPE(docType); //get doc type var getdocType="Doc type is"+doc.getDOCTYPE().toString(); var rootEl = ai.xml.createElement('Books'); //set root element doc.setRootElement(rootEl); //get root element var getroot="Root element is "+doc.getRootElement().toString(); //Combine the Doc type and the root element sentences to form a string var result = getdocType+"\n"+getroot; //send the string to a file on aws ai.awss3.putFile(bucketName, key, result.toString(), region, awsAccessKey, awsSecretKey); return true; } /* Output: Doc type is<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> Root element is <Books /> */