Modules
Objects/Functions
SuiteScript 2.0
N/xml Module
Member Type:
Name
Search NetSuite -
https://system.netsuite.com/app/help/helpcenter.nl?search=N/xml Module
// Code Example 1
Everyday Italian
Giada De Laurentiis
2005
30.00
Harry Potter
J K. Rowling
2005
29.99
XQuery Kick Start
James McGovern
Per Bothner
Kurt Cagle
James Linn
Vaidyanathan Nagarajan
2003
49.99
Learning XML
Erik T. Ray
2003
39.95
// Code Example 2
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
require(['N/xml', 'N/file'], function(xml, file) {
return {
onRequest: function(options) {
var sentence = '';
var xmlFileContent = file.load('SuiteScripts/BookSample.xml').getContents();
var xmlDocument = xml.Parser.fromString({
text: xmlFileContent
});
var bookNode = xml.XPath.select({
node: xmlDocument,
xpath: '//b:book'
});
for (var i = 0; i < bookNode.length; i++) {
var title = bookNode[i].firstChild.nextSibling.textContent;
var author = bookNode[i].getElementsByTagName({
tagName: 'b:author'
})[0].textContent;
sentence += 'Author: ' + author + ' wrote ' + title + '.\n';
}
options.response.write(sentence);
}
};
});
// Code Example 3
Author: Giada De Laurentiis wrote Everyday Italian.
Author: J K. Rowling wrote Harry Potter.
Author: James McGovern wrote XQuery Kick Start.
Author: Erik T. Ray wrote Learning XML.
// Code Example 4
/**
* @NApiVersion 2.x
* @NScriptType Suitelet
*/
require(['N/xml'], function(xml) {
return {
onRequest: function(options) {
var xmlString = 'Some content ';
var xmlDocument = xml.Parser.fromString({
text: xmlString
});
var bookNode = xml.XPath.select({
node: xmlDocument,
xpath: '//config'
});
for (var i = 0; i < bookNode.length; i++) {
log.debug('Config content', bookNode[i].textContent);
}
}
};
});
// Code Example 5
/**
* @NApiVersion 2.x
*/
require(['N/xml'], function(xml) {
var bookShelf = xml.Parser.fromString(file.load('SuiteScripts/books.xml').getContents());
var newBookNode = xmlData.createElement("book");
var newTitleNode = xmlData.createElement("title");
var newTitleNodeValue = xmlData.createTextNode("");
var newAuthorNode = xmlData.createElement("author");
var newAuthorNodeValue = xmlData.createTextNode("");
newTitleNode.appendChild(newTitleNodeValue);
newAuthorNode.appendChild(newAuthorNodeValue);
newBookNode.appendChild(newTitleNode);
newBookNode.appendChild(newAuthorNode);
var newbook = bookShelf.appendChild({
newChild: newBookNode
});
});
//SOURCE: https://system.netsuite.com/app/help/helpcenter.nl?fid=section_4344917661.html