%META:TOPICPARENT{name="OATDOCIndex"}% ---+ xml.js Useful function for XML access and manipulation. %TOC% ---++ Functions ---+++ OAT.Xml.createXmlDoc(string) Parses a string of XML data and returns a document object. ---+++ OAT.Xml.transformXSLT(xmlDoc, xslDoc[, paramsArray]) Applies a XSLT template. xslDoc is a template to be applied to xmlDoc. Both arguments must be valid XML documents (not strings). The third (optional) argument is an array of XSLT parameters. Each parameter is a triple (array), which consists of Namespace, Name, and Value. ---+++ OAT.Xml.textValue(node) Returns a text value of node. So, for the markup below, the textValueof tag is content -- content ---+++ OAT.Xml.localName(node) Returns node's local name - the part without namespace prefix.<xsl:template> has a localName template. ---+++ OAT.Xml.childElements(node) Returns all child nodes which are ordinary elements (i.e., no#textnodes, etc.). ---+++ OAT.Xml.getElementsByLocalName(node, localName) Identical to getElementsByTagName, but looks only into non-namespace part of tag name. ---+++ OAT.Xml.getLocalAttribute(node, attributeName) Returns a value of attribute whose non-prefixed name is attributeName ---+++ OAT.Xml.removeDefaultNamespace(string) Takes an XML document in string form and removes default namespace. This is useful when we want to use XPath queries against such a document, since these cannot be executed against documents with default namespaces. Returns XML string. ---+++ OAT.Xml.xpath(xmlDoc, xPathQuery, nsObject) Runs an XPath query (xPathQuery) against xmlDoc. Namespaces are resolved as properties of nsObject. ---+++ OAT.Xml.escape(xml) Returns escaped. ---+++ OAT.Xml.unescape(txt) Returns unescaped. ---++ Examples ---+++ Example 1 var xmlDoc, xslDoc; // somehow fill these with data var params = [ ["myNS","myparam1","myvalue1"], ["myNS","myparam2","myvalue2"] ] var result = OAT.Xml.transformXSLT(xmlDoc, xslDoc, params); ---+++ Example 2 var xmlString = 'value'; var xmlDoc = OAT.Xml.createXmlDoc(xmlString); var nodeArray = OAT.Xml.xpath(xmlDoc, '//node', {}); alert(nodeArray.length); // 2 CategoryDocumentation CategoryOAT CategoryOpenSource