Index | OAT homepage | OpenLink Software

# OATDOCxml

- OATDOCxml
- _ _ xml.js
- _ _ _ _ Functions
- _ _ _ _ _ _ OAT.Xml.createXmlDoc(string)
- _ _ _ _ _ _ OAT.Xml.transformXSLT(xmlDoc, xslDoc[, paramsArray])
- _ _ _ _ _ _ OAT.Xml.textValue(node)
- _ _ _ _ _ _ OAT.Xml.localName(node)
- _ _ _ _ _ _ OAT.Xml.childElements(node)
- _ _ _ _ _ _ OAT.Xml.getElementsByLocalName(node, localName)
- _ _ _ _ _ _ OAT.Xml.getLocalAttribute(node, attributeName)
- _ _ _ _ _ _ OAT.Xml.removeDefaultNamespace(string)
- _ _ _ _ _ _ OAT.Xml.xpath(xmlDoc, xPathQuery, nsObject)
- _ _ _ _ _ _ OAT.Xml.escape(xml)
- _ _ _ _ _ _ OAT.Xml.unescape(txt)
- _ _ _ _ Examples
- _ _ _ _ _ _ Example 1
- _ _ _ _ _ _ Example 2

## xml.js

Useful function for XML access and manipulation.

### 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 this markup --

    <tag>content</tag>

-- the `textValue` of `tag` is `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 `#text` nodes, 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 = '<?xml version="1.0" ?><document><node>value</node><node /></document>';
    var xmlDoc = OAT.Xml.createXmlDoc(xmlString);
    var nodeArray = OAT.Xml.xpath(xmlDoc, '//node', {});
    alert(nodeArray.length); // 2

Copyright (C) 2005-2008 OpenLink Software