Skip to main content
Adaptive Insights
Knowledge and Support - Adaptive Insights

Adaptive XML

ai.xml

Method

Parameters

Returns

Description

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

// constructing an Intacct authentication XML request


//'<request><control><senderid>adaptiveplanning</senderid><password>Bts9DrRkeZ</password><controlid>SomeRandomThingToMatchToResponse</controlid><dtdversion>3.0</dtdversion></control><operation><authentication><login><userid>Julia</userid><companyid>companyplanning-DEV</companyid><password>GhY93tYi</password></login></authentication></operation></request>'


// create XML document
var doc = ai.xml.createDocument();


// create root element and assign as the doc root
var requestEl = ai.xml.createElement('request');
doc.setRootElement(requestEl);


// control xml
var controlEl = ai.xml.createElement('control');
var senderIdEl = ai.xml.createElement('senderid');
senderIdEl.setText('adaptiveplanning');
controlEl.addChildElement(senderIdEl);


var controlPasswordEl = ai.xml.createElement('password');
controlPasswordEl.setText('Bts9DrRkeZ');
controlEl.addChildElement(controlPasswordEl);


var controlIdEl = ai.xml.createElement('controlid');
controlIdEl.setText('SomeRandomThingToMatchToResponse');
controlEl.addChildElement(controlIdEl);


var dtdEl = ai.xml.createElement('dtdversion');
dtdEl.setText('3.0');
controlEl.addChildElement(dtdEl);


// operation xml


//TODO

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.

 

Examples

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

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.

 

Examples

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">'); doc.setDOCTYPE(docType);

var rootEl = ai.xml.createElement('Books');
doc.setRootElement(rootEl);
alert(doc.toString()); // produces  '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"><Books></Books>';

ai.xml.docType

Method

Parameters

Returns

Description

toString()

 

String

Provides a string representation of this document type declaration.

 

Examples

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">');
doc.setDOCTYPE(docType);


alert(docType.toString()); // produces  '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">';

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

var tablesElement = ai.xml.createElement('Tables');


var table1Element = ai.xml.createElement('Table');
table1Element.setAttribute('remoteId','123');
table1Element.setText('This is some text');


tablesElement.addChildElement(table1Element);


alert(tablesElement.toString()); // produces '<tables><table remoteId="123">This is some text</table></tables>'

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.

 

Examples

var attribute1 = ai.xml.createAttribute('age', '30');


var attribute2 = attribute1.clone();
attribute2.setName('height');
attribute2.setValue('1.8');


alert(attribute1.toString()); // produces - 'age="30"'
alert(attribute2.toString()); // produces - 'height="1.8"'
  • Was this article helpful?