This is an example on how to use the XML API nlapiSelectValues on an XML Object.
Sample Code snippet:
//declare a variable that will hold the XML in the form of a string
var xmlStringVar = '<?xml version="1.0" encoding="ISO-8859-1"?>';
xmlStringVar = xmlStringVar + '<bookstore>';
xmlStringVar = xmlStringVar + '<book category="cooking">';
xmlStringVar = xmlStringVar + '<title lang="en">Everyday Italian</title>';
xmlStringVar = xmlStringVar + '<author>Giada De Laurentiis</author>';
xmlStringVar = xmlStringVar + '<year>2005</year>';
xmlStringVar = xmlStringVar + '<price>30.00</price>';
xmlStringVar = xmlStringVar + '</book>';
xmlStringVar = xmlStringVar + '<book category="cooking">';
xmlStringVar = xmlStringVar + '<title lang="sp">Chef At Home</title>';
xmlStringVar = xmlStringVar + '<author>Michael Smith</author>';
xmlStringVar = xmlStringVar + '<year>2010</year>';
xmlStringVar = xmlStringVar + '<price>29.95</price>';
xmlStringVar = xmlStringVar + '</book>';
xmlStringVar = xmlStringVar + '<book category="gardening">';
xmlStringVar = xmlStringVar + '<title lang="fr">Orchids For Life</title>';
xmlStringVar = xmlStringVar + '<author>Gardener Sam</author>';
xmlStringVar = xmlStringVar + '<year>2008</year>';
xmlStringVar = xmlStringVar + '<price>9.95</price>';
xmlStringVar = xmlStringVar + '</book>';
xmlStringVar = xmlStringVar + '</bookstore>';
//convert the string data into XML using nlapiStringToXML
var xmlData = nlapiStringToXML(xmlStringVar);
//declare a variable that will hold the XPATH (for more information about XPATH, click here)
path = "/bookstore/book/price"; //can also be "//price"
//declare a variable that will hold the selected values
var strArrData = nlapiSelectValues(xmlData, path );
//RESULT:
//strArrData will have the value ['30.00','29.95','9.95']
No comments:
Post a Comment