Straatos XML API

This article describes Straatos XML API

New XML Document

Create new XML document. The documentElementName can contain namespace prefix (e.g. ns:company) if documentElementNamespace is provided. The documentElementNamespace is optional — for elements without namespace this parameter should not be specified.

Input Parameters

Name
Description

string ElementName

Name of root element

string Namespace

[Optional] Namespace of element

Sample Code

var xmlnsDocument = straatos.newXMLDocument('ns:root', 'https://www.cumuluspro.com/api/1.0');

console.log(xmlDocument.xml);

Result

<?xml version="1.0" encoding="UTF-8" standalone="no"?>

<ns:root xmlns:ns="https://www.cumuluspro.com/api/1.0"/>

Parse XML

Parse data parameter (either a byte[] or string) containing XML and returns XML document.

Input Parameters

Name
Description

string Xml

XML string

Sample Code

Sample Code with XML Namespace

Result

XML document object


Add Element

Adds child element to current element. If namespaceURI is specified, name can contain a prefix, e.g. ns:company. For elements without namespace, no namespaceURI should be specified.

Input Parameters

Name
Description

string ElementName

Name of element

string Namespace

[Optional] Namespace of element

Sample Code

Result


Select Multiple Elements

Select elements using given XPath expression, relative to current element. Optionally, namespaces can be specified, e.g. { 'ns': 'urn:my—urn', 'ns2': 'urn:my-urn-2' }.

Input Parameters

Name
Description

string Xpath

Xpath of element

Namespace

[Optional] Namespace prefix: namespace of element

Sample Code

Sample Code with XML Namespace

Result

element at index 0: element value 1element at index 1: element value 2.

Result with XML Namespace

element at index 0: ns:element value 1.

element at index 1: ns:element value 2.


Select Single Element

Select first element matching given XPath expression, relative to current element. Optionally, namespaces can be specified, e.g. { 'ns': 'urn:my—urn', 'ns2': 'my-urn-2' }.

Input Parameters

Name
Description

string Xpath

Xpath of element

Namespace

[Optional] Namespace prefix: Namespace of element

Sample Code

Example with XML Namespace

Result

element value 1.

Result with XML Namespace

ns:element value 1.


Remove Element

Removes element from document.

Sample Code

Result


Add Attribute

Adds a new attribute to element. If namespaceURI is specified, name can contain prefix, e.g. ns:attr. For attributes without namespace, no namespaceURI should be specified.

Input Parameters

Name
Description

string AttributeName

Attribute Name

string AttributeValue

Attribute value

string NameSpace

[Optional] Namespace of element

Sample Code

Sample Code with XML Namespace

Result

Result with XML Namespace


Select Attribute

Evaluates XPath expression relative to current element. Optionally, namespace can be specified.

Input Parameters

Name
Description

string AttributeName

Attribute name

Namespace

[Optional] Namespace prefix: Namespace of element

Sample Code

Example with XML Namespace

Result

xpath string attr: attribute value.

Result with XML Namespace

xpath string attr: attribute value.


Select Element using Attribute

Evaluates XPath expression relative to current element. Optionally, namespace can be specified.

Input Parameters

Name
Description

string AttributeFilter

Attribute filter.

Namespace

[Optional] Namespace prefix: Namespace of element.

Sample Code

Example with XML Namespace

Result

xpath string query by attr: element value 2.

Result with XML Namespace

xpath string query by attr: ns:element value 2.


Remove Attribute

Removes attribute by name.

Input Parameters

string AttribueName.

Sample Code

Result

Last updated