Passa al contenuto principale
Adaptive Planning
Ultimo aggiornamento: 2024-09-20
ai.xml

ai.xml

Funzioni

Metodo
Parametri
Resi
Descrizione
createFromUrl(url, method, body, headers, callback)
disponibile a partire da 2018.3
url: String URL valido
method: String Metodo HTTP valido
body: Stringa il corpo della richiesta
headers: String HTTP Header
callback: funzione Oggetto A
ai.xml.sax
Crea un oggetto parser SAX XML in grado di analizzare un flusso XML.
createFromUrlWithAuthorisation(url, method, body, headers, callbacks)
disponibile a partire da 2018.3
url: String URL valido
method: String Metodo HTTP valido
body: Stringa il corpo della richiesta
headers: String HTTP Header
callback: funzione Oggetto A
ai.xml.sax
Crea un oggetto parser SAX XML in grado di analizzare un flusso XML con autorizzazione utilizzando OAuth.
createParser()
ai.xml.parser
Crea un oggetto parser XML in grado di analizzare le stringhe XML.
createDocument()
ai.xml.document
Crea un documento XML.
createDocType( xmlStr )
  • xmlStr : String Stringa XML DOCTYPE valida
ai.xml.docType
Creare un oggetto doctype da aggiungere a un documento XML per definirne il tipo.
createElement( name)
  • name : String Nome dell'elemento XML
ai.xml.element
Creare un elemento XML, che è l'elemento costitutivo di base di un documento XML, che può essere aggiunto a un documento XML.
createAttribute( name, value )
  • name : String Nome dell'attributo
  • value : String Valore dell'attributo
ai.xml.attribute
Crea un oggetto attributo che può essere aggiunto a un elemento XML.
Esempi
// 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

Metodo
Parametri
Resi
Descrizione
createFromText()
XML:string
Codifica: UTF8
Callback: un oggetto con funzioni
ai.xml.sax
Crea un oggetto parser SAX XML in grado di analizzare il testo XML.
Limitato a 2,5 milioni di caratteri.
createFromUrl()
url: String URL valido
method: String Metodo HTTP valido
body: Stringa il corpo della richiesta
headers: String HTTP Header
callback: un oggetto con funzioni
ai.xml.sax
Crea un oggetto parser SAX XML in grado di analizzare un flusso XML.
createFromUrlWithAuthorisation()
url: String URL valido
method: String Metodo HTTP valido
body: Stringa il corpo della richiesta
headers: String HTTP Header
callback: un oggetto con funzioni
ai.xml.sax
Crea un oggetto parser SAX XML in grado di analizzare un flusso XML con autorizzazione utilizzando OAuth.
Il
ai.xml.sax
utilizzare gli esempi seguenti
callbacks
. Una callback è una funzione che viene eseguita al termine dell'esecuzione di un'altra funzione. Uno dei vantaggi dell'utilizzo dei callback con i parser ai.xml.sax è che è possibile rilevare gli errori e presentarli nei registri di un'esecuzione di un'origine dati cloud privata per facilitare la risoluzione dei problemi.
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); };
esempio 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

Metodo
Parametri
Resi
Descrizione
parse( xmlStr )
  • xmlStr Stringa di documento XML valida
ai.xml.document
Analizza una stringa di documento XML valida in un documento XML.
Esempio di analisi
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

Metodo
Parametri
Resi
Descrizione
clone()
ai.xml.document
Restituisce un clone del documento.
getDOCTYPE()
ai.xml.docType
Ottiene il documento DOCTYPE.
getRootElement()
ai.xml.element
Ottiene l'elemento radice nel documento.
setDOCTYPE( docType )
  • docType : ai.xml.docType DOCTYPE per impostare il documento
Imposta il documento DOCTYPE.
setRootElement( element )
  • element : ai.xml.element Elemento come elemento radice del documento.
Imposta l'elemento radice del documento.
toString()
Fornisce una rappresentazione in formato stringa formattata del documento XML.

ai.xml.docType

Metodo
Parametri
Resi
Descrizione
toString()
String
Fornisce una rappresentazione in formato stringa della dichiarazione del tipo di documento.
Esempio
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

Metodo
Parametri
Resi
Descrizione
addChildElement( element )
  • element : ai.xml.element Elemento da aggiungere
Aggiunge un elemento figlio.
clone()
ai.xml.element
Restituisce un clone di questo elemento.
getAttribute( name )
name : String Nome dell'attributo
ai.xml.attribute
Ottiene l'attributo del nome specificato.
getAttributeAt( index )
index : intero Indice dell'attributo
ai.xml.attribute
Ottiene l'attributo in corrispondenza dell'indice specificato della matrice degli attributi per questo elemento.
getAttributes()
Array<ai.xml.attribute>
Ottiene gli attributi di questo elemento.
getAttributeValue( name )
  • name : String Nome dell'attributo
String
Ottiene il valore dell'attributo del nome specificato.
getChildElement( name )
  • name : String Nome dell'elemento
ai.xml.element
Ottiene il primo elemento figlio con il nome specificato.
getChildElementAt( index )
  • index : intero Indice dell'elemento
ai.xml.element
Ottiene un elemento figlio in corrispondenza dell'indice specificato all'interno degli elementi figlio.
getChildElements()
Array<ai.xml.elements>
Ottiene la matrice di tutti gli elementi figlio per questo elemento.
getChildElements( name )
  • name : String Nome degli elementi
Array<ai.xml.element>
Ottiene la matrice di elementi figlio per questo elemento con il nome specificato.
getCommentText()
String
Ottiene il testo del commento.
getName()
String
Ottiene il nome completo di questo elemento.
getText()
String
Ottiene il testo di questo elemento o CDATA.
hasContents()
Booleano
Indica se questo elemento ha contenuti figlio: testo, CDATA o elementi figlio.
removeAllAttributes()
Rimuove tutti gli attributi da questo elemento.
removeAttribute( name)
  • name : String Nome dell'attributo
Rimuove l'attributo del nome specificato nella matrice degli attributi dell'elemento e ricomprime la matrice.
removeChildElement( name )
  • name : String Nome dell'elemento
Rimuove il primo elemento figlio con il nome specificato.
removeChildElementAt( index )
  • index : intero Indice dell'elemento
Rimuove un elemento figlio in corrispondenza dell'indice specificato all'interno degli elementi figlio.
removeChildElements()
Intero
Rimuove tutti gli elementi figlio da questo elemento e restituisce il numero di elementi rimossi.
removeChildElements( name )
  • name : String Nome degli elementi
Intero
Rimuove tutti gli elementi figlio del nome dell'elemento specificato da questo elemento e restituisce il numero di elementi rimossi.
removeComments()
Rimuove tutti i commenti allegati direttamente a questo elemento.
removeText()
Rimuove tutto il testo (incluse le sezioni CDATA) allegato direttamente a questo elemento.
setAttribute( attribute)
  • attribute: ai.xml.attribute L'oggetto attributo da aggiungere
Aggiunge un attributo a questo elemento.
setAttribute(name, value )
  • name : String Nome dell'attributo
  • value : String Valore dell'attributo
Imposta il valore dell'attributo del nome specificato per questo elemento.
setCDATAText( text )
  • text : stringa di testo CDATA
Rimuove tutto il contenuto esistente (tranne i commenti) da questo elemento, inclusi gli elementi figlio, e quindi imposta il testo della sezione CDATA per questo elemento.
setCommentText( text )
  • text : String Testo del commento
Rimuove tutti i commenti allegati direttamente a questo elemento, quindi aggiunge un nuovo commento con il testo specificato.
setName( name)
  • name : String Nome dell'elemento
Imposta il nome di questo elemento.
setText( text )
  • text : String Valore di testo dell'elemento
Rimuove tutto il contenuto esistente (tranne i commenti) da questo elemento, inclusi gli elementi figlio, e quindi imposta il testo dell'elemento.
toString()
Fornisce una rappresentazione in formato stringa formattata di questo elemento.
Esempi
Esempio di 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> */
Esempio per getChildElement(), getChildElementAt(), getChildElements e 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>
Esempi di hasContents(), removeChildElement( name ), removeChildElementAt(index), removeChildElements() e 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

Metodo
Parametri
Resi
Descrizione
clone()
ai.xml.attribute
Restituisce un clone di questo attributo.
getName()
String
Ottiene il nome dell'attributo.
getValue()
String
Ottiene il valore dell'attributo.
setName( name)
  • name : String Nome dell'attributo
Imposta il nome dell'attributo.
setValue( value )
  • value : String Valore dell'attributo
Imposta il valore dell'attributo.
toString()
Restituisce una rappresentazione in formato stringa di questo attributo.
Esempio
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/> */

Visualizzare i log di output XML con AWS S3

È necessario analizzare l'XML di esempio prima di registrare i risultati con i metodi ai.log. Per visualizzare esempi XML non elaborati, convertire il file in una stringa con
toString()
e visualizzare il file nel bucket AWS S3.
Utilizzare l'esempio seguente per connettersi all'istanza AWS S3 per creare e visualizzare i risultati XML. Saranno necessari i valori nome dell'intervallo, chiave, chiave di accesso, chiave privata e area geografica. Per ulteriori informazioni e codici di esempio, consultare ai.awss3
Esempio
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 /> */