Saltar al contenido principal
Adaptive Planning
Última actualización: 2024-09-20
ai.xml

ai.xml

Funciones

Método
Parámetros
Devoluciones
Descripción
createFromUrl(url, method, body, headers, callbacks)
disponible a partir de 2018,3
url: cadena URL válida
method: String Método HTTP válido
body: cuerpo de solicitud de cadena
headers: cabecera HTTP de cadena
devoluciones de llamada: función de objeto A
ai.xml.sax
Crea un objeto de analizador XML SAX que puede analizar una secuencia XML.
createFromUrlWithAuthorisation(url, método, cuerpo, cabeceras, devoluciones de llamada)
disponible a partir de 2018,3
url: cadena URL válida
method: String Método HTTP válido
body: cuerpo de solicitud de cadena
headers: cabecera HTTP de cadena
devoluciones de llamada: función de objeto A
ai.xml.sax
Crea un objeto de analizador XML SAX que puede analizar una secuencia XML con autorización mediante OAuth.
createParser()
ai.xml.parser
Crea un objeto de analizador XML que puede analizar cadenas XML.
createDocument()
ai.xml.document
Crea un documento XML.
createDocType( xmlStr )
  • xmlStr : String Cadena XML DOCTYPE válida
ai.xml.docType
Cree un objeto de tipo de documento que se añada a un documento XML para definir su tipo de documento.
createElement( nombre )
  • name : Nombre de cadena del elemento XML
ai.xml.element
Cree un elemento XML, que es el componente básico de un documento XML, que se puede añadir a un documento XML.
createAttribute( name, value )
  • name : Nombre de cadena del atributo
  • value : Valor de cadena del atributo
ai.xml.attribute
Crea un objeto de atributo que se puede añadir a un elemento XML.
Ejemplos
// 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

Método
Parámetros
Devoluciones
Descripción
createFromText()
XML:string
Codificación: UTF8
Devoluciones de llamada: un objeto con funciones
ai.xml.sax
Crea un objeto de analizador XML SAX que puede analizar texto XML.
Limitado a 2,5 millones de caracteres.
createFromUrl()
url: cadena URL válida
method: String Método HTTP válido
body: cuerpo de solicitud de cadena
headers: cabecera HTTP de cadena
callbacks: un objeto con funciones
ai.xml.sax
Crea un objeto de analizador XML SAX que puede analizar una secuencia XML.
createFromUrlWithAuthorisation()
url: cadena URL válida
method: String Método HTTP válido
body: cuerpo de solicitud de cadena
headers: cabecera HTTP de cadena
callbacks: un objeto con funciones
ai.xml.sax
Crea un objeto de analizador XML SAX que puede analizar una secuencia XML con autorización mediante OAuth.
El
ai.xml.sax
los siguientes ejemplos utilizan
callbacks
. Una devolución de llamada es una función que se ejecuta después de que otra función termine de ejecutarse. Una de las ventajas de utilizar devoluciones de llamada con analizadores ai.xml.sax es que puede detectar errores y presentarlos en los registros de una ejecución de CCDS para facilitar la resolución de problemas.
Ejemplo de ai.xml.sax.createFromText
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); };
Ejemplo de ai.xml.sax.createFromUrl
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

Método
Parámetros
Devoluciones
Descripción
parse( xmlStr )
  • xmlStr Cadena de documento XML válida
ai.xml.document
Analiza una cadena de documento XML válida en un documento XML.
Ejemplo de análisis
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

Método
Parámetros
Devoluciones
Descripción
clone()
ai.xml.document
Devuelve un clon de este documento.
getDOCTYPE()
ai.xml.docType
Obtiene el documento DOCTYPE.
getRootElement()
ai.xml.element
Obtiene el elemento raíz del documento.
setDOCTYPE( docType )
  • docType : ai.xml.docType DOCTYPE para definir el documento como
Establece el documento DOCTYPE.
setRootElement( element )
  • element : ai.xml.element Elemento para que sea el elemento raíz del documento.
Establece el elemento raíz del documento.
toString()
Proporciona una representación de cadena con formato del documento XML.

ai.xml.docType

Método
Parámetros
Devoluciones
Descripción
toString()
Cadena
Proporciona una representación de cadena de esta declaración de tipo de documento.
Ejemplo
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

Método
Parámetros
Devoluciones
Descripción
addChildElement( element )
  • element : ai.xml.element Elemento para añadir
Añade un elemento secundario.
clone()
ai.xml.element
Devuelve un clon de este elemento.
getAttribute( nombre )
name : Nombre de cadena del atributo
ai.xml.attribute
Obtiene el atributo del nombre dado.
getAttributeAt( index )
index : índice entero de atributo
ai.xml.attribute
Obtiene el atributo en el índice especificado de la matriz de atributos de este elemento.
getAttributes()
Array<ai.xml.attribute>
Obtiene los atributos de este elemento.
getAttributeValue( nombre )
  • name : Nombre de cadena del atributo
Cadena
Obtiene el valor del atributo del nombre dado.
getChildElement( name )
  • name : String Nombre del elemento
ai.xml.element
Obtiene el primer elemento secundario que tiene el nombre especificado.
getChildElementAt( index )
  • index : índice entero del elemento
ai.xml.element
Obtiene un elemento secundario en el índice especificado dentro de los elementos secundarios.
getChildElements()
Array<ai.xml.elements>
Obtiene la matriz de todos los elementos secundarios de este elemento.
getChildElements( name )
  • name : String Nombre de los elementos
Array<ai.xml.element>
Obtiene la matriz de elementos secundarios de este elemento con el nombre especificado.
getCommentText()
Cadena
Obtiene el texto del comentario.
getName()
Cadena
Obtiene el nombre calificado de este elemento.
getText()
Cadena
Obtiene el texto de este elemento o CDATA.
hasContents()
Booleano
Indica si este elemento tiene o no contenido secundario: texto, CDATA o elementos secundarios.
removeAllAttributes()
Elimina todos los atributos de este elemento.
removeAttribute( name )
  • name : Nombre de cadena del atributo
Elimina el atributo del nombre dado en la matriz de atributos de elemento y vuelve a comprimir la matriz.
removeChildElement( name )
  • name : String Nombre del elemento
Elimina el primer elemento secundario con el nombre especificado.
removeChildElementAt( index )
  • index : índice entero del elemento
Elimina un elemento secundario en el índice especificado dentro de los elementos secundarios.
removeChildElements()
Valor entero
Elimina todos los elementos secundarios de este elemento y devuelve el recuento de elementos eliminados.
removeChildElements( name )
  • name : String Nombre de los elementos
Valor entero
Elimina todos los elementos secundarios del nombre de elemento dado de este elemento y devuelve el recuento de elementos eliminados.
removeComments()
Elimina todos los comentarios adjuntos directamente a este elemento.
removeText()
Elimina todo el texto (incluidas las secciones CDATA) adjunto directamente a este elemento.
setAttribute(atributo)
  • atributo : ai.xml.attribute El objeto de atributo que se va a añadir
Añade un atributo a este elemento.
setAttribute(name, value)
  • name : Nombre de cadena del atributo
  • value : Valor de cadena del atributo
Establece el valor del atributo del nombre de pila para este elemento.
setCDATAText( text )
  • text : String CDATA text
Elimina todo el contenido existente (excepto los comentarios) de este elemento, incluidos los elementos secundarios, y luego establece el texto de la sección CDATA para este elemento.
setCommentText( text )
  • text : Texto de comentario de cadena
Elimina todos los comentarios adjuntos directamente a este elemento y, a continuación, añade un nuevo comentario con el texto proporcionado.
setName( name )
  • name : String Nombre del elemento
Establece el nombre de este elemento.
setText( texto )
  • text : Valor de texto de cadena del elemento
Elimina todo el contenido existente (excepto los comentarios) de este elemento, incluidos los elementos secundarios, y luego establece el texto del elemento.
toString()
Proporciona una representación de cadena con formato de este elemento.
Ejemplos
Ejemplo de 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> */
Ejemplo de getChildElement(), getChildElementAt(), getChildElements y 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>
Ejemplos de hasContents(), removeChildElement( name ), removeChildElementAt(index), removeChildElements() y 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

Método
Parámetros
Devoluciones
Descripción
clone()
ai.xml.attribute
Devuelve un clon de este atributo.
getName()
Cadena
Obtiene el nombre del atributo.
getValue()
Cadena
Obtiene el valor del atributo.
setName( name )
  • name : Nombre de cadena del atributo
Establece el nombre del atributo.
setValue( value )
  • value : Valor de cadena del atributo
Establece el valor del atributo.
toString()
Devuelve una representación de cadena de este atributo.
Ejemplo
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/> */

Consulta de registros de salida XML con AWS S3

Debe analizar el XML de muestra antes de registrar los resultados con los métodos ai.log. Para ver ejemplos de XML sin formato, convierta el archivo en una cadena con
toString()
y consulte el archivo en su bucket de AWS S3.
Utilice el siguiente ejemplo para conectarse a su instancia de AWS S3 para crear y consultar sus resultados XML. Necesitará el nombre de bucket, la clave, la clave de acceso, la clave secreta y los valores de región. Para obtener más información y códigos de ejemplo, consulte ai.awss3.
Ejemplo
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 /> */