Document Object Members

Learn about Document Object Members for XML manipulation in NetSuite SuiteScript. This includes methods to create and manage XML elements efficiently.

·3 min read·View Oracle Docs

The Document Object in the N/xml module allows developers to manipulate and manage XML documents within NetSuite SuiteScript. It provides a rich set of methods to create, modify, and read XML data structures effectively, catering to both client and server script contexts.

What is the Document Object?

The xml.Document object represents an entire XML document. The XML Document Object Model (DOM) organizes a document as a hierarchical structure comprising various node objects. This organization facilitates the manipulation of XML documents by exposing a comprehensive API.

Key Members of the Document Object

The following are the important methods and properties available on the xml.Document object:

Member TypeNameReturn TypeSupported Script TypesDescription
MethodDocument.adoptNode(options)[xml.Node](#)Client and server scriptsAttempts to adopt a node from another document to the current document.
MethodDocument.createAttribute(options)[xml.Attr](#)Client and server scriptsCreates an attribute node of type ATTRIBUTE_NODE with an optional specified value.
MethodDocument.createCDATASection(options)[xml.Node](#)Client and server scriptsCreates a CDATA section node with the specified data.
MethodDocument.createElement(options)[xml.Element](#)Client and server scriptsCreates a new node of type ELEMENT_NODE with the specified name.
PropertyDocument.documentElement[xml.Element](#) (read-only)Client and server scriptsRepresents the root node of the XML document.
PropertyDocument.xmlStandalonebooleanClient and server scriptsReturns true if the current XML document is standalone (i.e., not dependent on external references).

Example Usage

To create a new XML document and add elements to it, you can use the following SuiteScript code:

suitescript
1var xmlDoc = xml.createDocument();
2var rootElement = xmlDoc.createElement({name: 'root'});
3xmlDoc.appendChild(rootElement);
4
5var childElement = xmlDoc.createElement({name: 'child'});
6rootElement.appendChild(childElement);

Inheritance from Node Object

The xml.Document object inherits from the xml.Node object, allowing for utilization of node-level methods and properties seamlessly. This design enhances flexibility when working with XML structures.

Further Exploration

Developers can utilize this object in conjunction with other components of the N/xml module, such as xml.Element, xml.Attr, and more, to create powerful XML processing tools within their SuiteScript applications.

Who This Affects

  • Developers: Engage with XML processing in SuiteScript.
  • Administrators: May support integrations that require XML handling.
  • Technical Teams: Develop custom solutions leveraging XML data structures.

Key Takeaways

  • The xml.Document object provides a robust interface for XML manipulation in SuiteScript.
  • It supports a variety of methods for creating and managing XML structures effectively.
  • Understanding XML document hierarchy is crucial for leveraging this functionality optimally.

Source: This article is based on Oracle's official NetSuite documentation.

Frequently Asked Questions (4)

Does the Document Object support both client and server scripts?
Yes, the Document Object methods and properties are supported in both client and server scripts.
What method is used to create a new element in XML when using the xml.Document object?
You can use the Document.createElement(options) method to create a new node of type ELEMENT_NODE with the specified name.
Is the documentElement property writable?
No, Document.documentElement is a read-only property representing the root node of the XML document.
Can xml.Document manage a node from a different document?
Yes, the Document.adoptNode(options) method attempts to adopt a node from another document to the current document.
Source: Document Object Members Oracle NetSuite Help Center. This article was generated from official Oracle documentation and enriched with additional context and best practices.

Was this article helpful?

More in Integration

View all Integration articles →