Document Object Members
Learn about Document Object Members for XML manipulation in NetSuite SuiteScript. This includes methods to create and manage XML elements efficiently.
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 Type | Name | Return Type | Supported Script Types | Description |
|---|---|---|---|---|
| Method | Document.adoptNode(options) | [xml.Node](#) | Client and server scripts | Attempts to adopt a node from another document to the current document. |
| Method | Document.createAttribute(options) | [xml.Attr](#) | Client and server scripts | Creates an attribute node of type ATTRIBUTE_NODE with an optional specified value. |
| Method | Document.createCDATASection(options) | [xml.Node](#) | Client and server scripts | Creates a CDATA section node with the specified data. |
| Method | Document.createElement(options) | [xml.Element](#) | Client and server scripts | Creates a new node of type ELEMENT_NODE with the specified name. |
| Property | Document.documentElement | [xml.Element](#) (read-only) | Client and server scripts | Represents the root node of the XML document. |
| Property | Document.xmlStandalone | boolean | Client and server scripts | Returns 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:
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.Documentobject 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.
Frequently Asked Questions (4)
Does the Document Object support both client and server scripts?
What method is used to create a new element in XML when using the xml.Document object?
Is the documentElement property writable?
Can xml.Document manage a node from a different document?
Was this article helpful?
More in SuiteScript
- SuiteScript 2.1 Enhancements in NetSuite February Updates
SuiteScript 2.1 now supports async features and PATCH method. Discover the latest API and SuiteProcurement improvements.
- Scheduling Map/Reduce Script Deployments in NetSuite
Learn to schedule map/reduce script submissions, including one-time and recurring options in NetSuite.
- Binary File Support in N/https Module for SuiteScript
SuiteScript enhances capabilities with binary file support in the N/https module, allowing improved data handling in external communications.
- API Governance Units Calculation in NetSuite 2026.1
NetSuite 2026.1 introduces examples illustrating API governance unit calculations for both user event and scheduled scripts.
