The N/xmlparser module provides a simple SAX-style or DOM-based XML parser for SuiteScript, useful for processing XML responses from external APIs or reading EDI/XML files from the File Cabinet.
Parsing XML Content
define(["N/xmlparser", "N/log"], (xmlparser, log) => {
const xmlString = "<response><status>success</status><orderId>98765</orderId></response>";
const parser = xmlparser.fromString({ text: xmlString });
const status = parser.getElementsByTagName({ tagName: "status" })[0].textContent;
const orderId = parser.getElementsByTagName({ tagName: "orderId" })[0].textContent;
log.debug("Status", status);
log.debug("Order ID", orderId);
return {};
});
N/xml vs N/xmlparser
| Feature | N/xml | N/xmlparser |
|---|---|---|
| Build XML | Yes β full DOM creation | No |
| Parse XML | Yes | Yes β simplified API |
| Validate XML | Yes (XSD validation) | No |
| Best for | Full XML manipulation | Quick XML reading |