N/xml Module

Use the N/xml module to validate, parse, read, and modify XML documents.

                                   

In This Help Topic

N/xml Module Members

Member Type

Name

Return Type / Value Type

Supported Script Types

Description

Object

xml.Parser

Object

Client and server scripts

Encapsulates the functionality used by NetSuite to parse XML.

xml.XPath

Object

Client and server scripts

Encapsulates the functionality used by NetSuite to run XPath expressions.

XPath is a standard for enumerating paths in an XML document collection.

xml.Node

Object

Client and server scripts

Represents a generic XML node in an XML document. A node can be a Document, Element, or Attribute.

xml.Document

Object

Client and server scripts

Represents an entire XML document. The XML DOM presents a document as a hierarchy of node objects. Use the methods and properties available to the xml.Document object to manipulate the XML document and the nodes in the document tree.

xml.Element

Object

Client and server scripts

Represents an element in an XML document. Elements may contain attributes, other elements, or text. If an element contains text, the text is represented in a text node of type TEXT_NODE.

xml.Attr

Object

Client and server scripts

Represents an attribute node of an xml.Element object.

Method

xml.escape(options)

string

Client and server scripts

Prepares a string for use in XML by escaping XML markup, such as angle brackets, quotation marks, and ampersands.

xml.validate(options)

void

Server scripts

Validates an XML document against an XML Schema (XSD).

Enum

xml.NodeType

string (read-only)

Client and server scripts

Holds the string values for the supported node types. Use this enum to set the Node.nodeType property.

Parser Object Members

The following members are called on the xml.Parser object.

Member Type

Name

Return Type / Value Type

Supported Script Types

Description

Method

Parser.fromString(options)

xml.Document

Client and server scripts

Parses a string into a W3C XML document object.

Parser.toString(options)

string

Client and server scripts

Converts (serializes) an xml.Document object into a string.

XPath Object Members

The following members are called on the xml.XPath object.

Member Type

Name

Return Type / Value Type

Supported Script Types

Description

Method

XPath.select(options)

xml.Node[]

Client and server scripts

Selects an array of nodes from an XML document using an XPath expression.

Node Object Members

The following members are called on the xml.Node object.

Member Type

Name

Return Type / Value Type

Supported Script Types

Description

Method

Node.appendChild(options)

xml.Node

Client and server scripts

Appends a node after the last child node of a specific element node. Returns the new child node.

Node.cloneNode(options)

xml.Node

Client and server scripts

Creates a copy of a node. Returns the copied node.

Node.compareDocumentPosition(options)

number

Client and server scripts

Returns a number that reflects where two nodes are located, compared to each other.

Node.hasAttributes()

boolean

Client and server scripts

Returns true if the current node has any attributes. Note that only element nodes can have attributes.

Node.hasChildNodes()

boolean

Client and server scripts

Returns true if the current node has child nodes or returns false if the current node does not have child nodes.

Node.insertBefore(options)

xml.Node

Client and server scripts

Inserts a new child node before an existing child node for the current node.

Node.isDefaultNamespace(options)

boolean

Client and server scripts

Returns true if the specified namespace uniform resource identifier (URI) is the default namespace for the current node or returns false if the specified namespace is not the default namespace.

Node.isEqualNode(options)

boolean

Client and server scripts

Returns true if two nodes are equal or returns false if two nodes are not equal.

Node.isSameNode(options)

boolean

Client and server scripts

Returns true if two nodes reference the same object or returns false if two nodes do not reference the same object.

Node.lookupNamespaceURI(options)

string

Client and server scripts

Returns the namespace uniform resource identifier (URI) that matches the specified namespace prefix.

Node.lookupPrefix(options)

string

Client and server scripts

Returns the namespace prefix associated with the specified namespace uniform resource identifier (URI).

Node.normalize()

void

Client and server scripts

Puts all text nodes underneath a node, including attribute nodes, into a normal form.

Node.removeChild(options)

xml.Node

Client and server scripts

Removes the specified child node. Returns the removed child node.

Node.replaceChild(options)

xml.Node

Client and server scripts

Replaces a specific child node with another child node in a list of child nodes.

Property

Node.attributes

Object (read-only)

Client and server scripts

Key-value pairs for all attributes for an xml.Element node. Returns null for all other node types.

Node.baseURI

string (read-only)

Client and server scripts

Absolute base uniform resource identifier (URI) of a node or null if the URI cannot be determined.

Node.childNodes

xml.Node[] (read-only)

Client and server scripts

Array of all child nodes of a node or an empty array if there are no child nodes.

Node.firstChild

xml.Node (read-only)

Client and server scripts

First child node for a specific node or null if there are no child nodes.

Node.lastChild

xml.Node (read-only)

Client and server scripts

Last child node for a specific node or null if there is no last child node.

Node.localName

string (read-only)

Client and server scripts

The local part of the qualified name of a node.

Node.namespaceURI

string (read-only)

Client and server scripts

The namespace uniform resource identifier (URI) of a node or null if there is no namespace URI for the node.

Node.nextSibling

xml.Node (read-only)

Client and server scripts

The next node in a node list or null if the current node is the last node.

Node.nodeName

string (read-only)

Client and server scripts

Name of a node, depending on the type. For example, for a node of type xml.Element, the name is the name of the element.

Node.nodeType

string

Client and server scripts

The type of node defined as a value from the xml.NodeType enum.

Node.nodeValue

string

Client and server scripts

The value of a node, depending on its type.

Node.ownerDocument

xml.Document (read-only)

Client and server scripts

The root element for a node as a xml.Document object.

Node.parentNode

xml.Node (read-only)

Client and server scripts

The parent node of a node.

Node.prefix

string

Client and server scripts

The namespace prefix of the node, or null if the node does not have a namespace.

Node.previousSibling

xml.Node (read-only)

Client and server scripts

The previous node in a node list or null if the current node is the first node.

Node.textContent

string

Client and server scripts

The textual content of a node and its descendants.

Document Object Members

Note:

In addition to the Document object members, Document objects inherit the members of the Node object. The methods and properties associated with a Node object can be used as members of a Document object. For more information, see Node Object Members.

The following members are called on the xml.Document object.

Member Type

Name

Return Type / Value Type

Supported Script Types

Description

Method

Document.adoptNode(options)

xml.Node

Client and server scripts

Attempts to adopt a node from another document to this document.

Document.createAttribute(options)

xml.Attr

Client and server scripts

Creates an attribute node of type ATTRIBUTE_NODE with the optional specified value.

Document.createAttributeNS(options)

xml.Attr

Client and server scripts

Creates an attribute node of type ATTRIBUTE_NODE, with the specified namespace value and optional specified value.

Document.createCDATASection(options)

xml.Node

Client and server scripts

Creates a CDATA section node of type DOCUMENT_FRAGMENT_NODE with the specified data.

Document.createComment(options)

xml.Node

Client and server scripts

Creates a Comment node of type COMMENT_NODE with the specified string.

Document.createDocumentFragment()

xml.Node

Client and server scripts

Creates a node of type DOCUMENT_FRAGMENT_NODE.

Document.createElement(options)

xml.Element

Client and server scripts

Creates a new node of type ELEMENT_NODE with the specified name.

Document.createElementNS(options)

xml.Element

Client and server scripts

Creates a new node of type ELEMENT_NODE with the specified namespace URI and name.

Document.createProcessingInstruction(options)

xml.Node

Client and server scripts

Creates a new node of type PROCESSING_INSTRUCTION_NODE with the specified target and data.

Document.createTextNode(options)

xml.Node

Client and server scripts

Creates a new node of type TEXT_NODE.

Document.getElementById(options)

xml.Element

Client and server scripts

Returns the element that has an ID attribute with the specified value as an xml.Element object.

Document.getElementsByTagName(options)

xml.Element[]

Client and server scripts

Returns an array of xml.Element objects with a specific tag name, in the order in which they appear in the XML document.

Document.getElementsByTagNameNS(options)

xml.Element[]

Client and server scripts

Returns an array of xml.Element objects with a specific tag name and namespace, in the order in which they appear in the XML document.

Document.importNode(options)

xml.Node

Client and server scripts

Imports a node from another document to this document. Creates a new copy of the source node.

Property

Document.doctype

Object (read-only)

Client and server scripts

Returns a node of type DOCUMENT_TYPE_NODE that represents the doctype of the XML document.

Document.documentElement

xml.Element (read-only)

Client and server scripts

Root node of the XML document.

Document.documentURI

string (read-only)

Client and server scripts

Location of the document or null if undefined.

Document.inputEncoding

string (read-only)

Client and server scripts

Encoding used for an XML document at the time the document was parsed.

Document.xmlEncoding

string (read-only)

Client and server scripts

Part of the XML declaration, the XML encoding of the XML document.

Document.xmlStandalone

boolean

Client and server scripts

Part of the XML declaration, returns true if the current XML document is standalone or returns false if it is not.

Document.xmlVersion

string

Client and server scripts

Part of the XML declaration, the version number of the XML document.

Element Object Members

Note:

In addition to the Element object members, Element objects inherit the members of the Node object. The methods and properties associated with a Node object can be used as members of a Element object. For more information, see Node Object Members.

The following members are called on the xml.Element object.

Member Type

Name

Return Type / Value Type

Supported Script Types

Description

Method

Element.getAttribute(options)

string

Client and server scripts

Returns the value of the specified attribute.

Element.getAttributeNode(options)

xml.Attr

Client and server scripts

Retrieves an attribute node by name.

Element.getAttributeNodeNS(options)

string

Client and server scripts

Returns an attribute node with the specified namespace URI and local name.

Element.getAttributeNS(options)

xml.Attr

Client and server scripts

Returns an attribute value with the specified namespace URI and local name.

Element.getElementsByTagName(options)

xml.Element[]

Client and server scripts

Returns an array of descendant xml.Element objects with a specific tag name, in the order in which they appear in the XML document.

Element.getElementsByTagNameNS(options)

xml.Element[]

Client and server scripts

Returns an array of descendant xml.Element objects with a specific tag name and namespace, in the order in which they appear in the XML document.

Element.hasAttribute(options)

boolean

Client and server scripts

Returns true if the current element has an attribute with the specified name or if that attribute has a default value. Otherwise, returns false.

Element.hasAttributeNS(options)

boolean

Client and server scripts

Returns true if the current element has an attribute with the specified local name and namespace or if that attribute has a default value. Otherwise, returns false.

Element.removeAttribute(options)

void

Client and server scripts

Removes the attribute with the specified name.

Element.removeAttributeNode(options)

xml.Attr

Client and server scripts

Removes the attribute specified as a xml.Attr object.

Element.removeAttributeNS(options)

void

Client and server scripts

Removes the attribute with the specified namespace URI and local name.

Element.setAttribute(options)

void

Client and server scripts

Adds a new attribute with the specified name. If an attribute with that name is already present in the element, its value is changed to the value specified in method argument.

Element.setAttributeNode(options)

xml.Attr

Client and server scripts

Adds the specified attribute node. If an attribute with the same name is already present in the element, it is replaced by the new one.

Element.setAttributeNodeNS(options)

xml.Attr

Client and server scripts

Adds the specified attribute node. If an attribute with the same local name and namespace URI is already present in the element, it is replaced by the new one.

Element.setAttributeNS(options)

void

Client and server scripts

Adds a new attribute with the specified name and namespace URI. If an attribute with the same name and namespace URI is already present in the element, its value is changed to the value specified in method argument.

Property

Element.tagName

string (read-only)

Client and server scripts

The tag name of this xml.Element object.

Attr Object Members

The following members are called on the xml.Attr object.

Member Type

Name

Return Type / Value Type

Supported Script Types

Description

Property

Attr.name

string (read-only)

Client and server scripts

The name of an attribute.

Attr.ownerElement

xml.Element (read-only)

Client and server scripts

The xml.Element object that is the parent of the xml.Attr object.

Attr.specified

boolean

Client and server scripts

Returns true if the attribute value is set in the parsed XML document, and false if it is a default value in a DTD or Schema.

Attr.value

string

Client and server scripts

Value of an attribute. The value of the attribute is returned as a string. Character and general entity references are replaced with their values.

Related Topics

SuiteScript 2.x Modules
SuiteScript 2.x

General Notices