Namespace: xml

bcdui.util. xml

Utilities for working with DOM

Methods

staticbcdui.util.xml.cloneElementContent(targetElement, sourceElement){Element}

util/xmlPackage.js, line 48
Copies all child elements and attributes from a source XML element to a target XML element.
Name Type Description
targetElement HtmlElement The element the content (child elements + attributes) of the source element should be copied to.
sourceElement HtmlElement The source for the elements and attributes copied under the target element.
Returns:
Type Description
Element The targetElement.

staticbcdui.util.xml.createElementWithPrototype(baseElement, path, enableWrsExtensions){Element}

util/xmlPackage.js, line 202
This function works similar to selectSingleNode in that executes an XPath on a DOMDocument or XML element and returns an XML element. However if the element does not exists it creates XML elements on the XPath so that the XPath returns an element afterwards. For example if the document contains only a root element and the path is
         /Root/Filter[@name = 'abc']/Item
it does the following:
  1. create an element "Filter" under the root node,
  2. set an attribute "name" with content "abc" on it,
  3. create an Item under it,
  4. return the Item. So the XPath "/Root/Filter[@name = 'abc']/Item" can be regarded as an XML prototype that is created if the element does not exist.

Please note that this function accepts only a very limited set of XPaths because otherwise the inversion of the XPath would be too complicated to be computed. For example it is not allowed to specify "//" in the XPath and the "or" conjunction cannot be used.

Name Type Default Description
baseElement DomDocument | DomElement | bcdui.core.DataProvider The DOM document or the XML element the path is evaluated on.
path modelXPath | String The XPath identifying the element to be retrieved or created.
enableWrsExtensions boolean true optional Set this flag to "true" if the function should treat wrs elements differently (like converting wrs:R to wrs:M or creating wrs:I elements). It is "true" by default.
Returns:
Type Description
Element The XML element to be found under the specified XPath.

staticbcdui.util.xml.getParentNode(node){Element}

util/xmlPackage.js, line 214
Determines the parent element of a node, no matter if it is an attribute node or an element. It is quite useful especially for attribute nodes, because the parentNode property does not work on them.
Name Type Description
node DomElement | DomAttribute
Returns:
Type Description
Element The parent element of the specified node.

staticbcdui.util.xml.nextElementSibling(element){Element}

util/xmlPackage.js, line 76
Computes which XML element is the next sibling of the given element. In contrast to the nextSibling DOM function this function does only return an XML element (not a comment, text node etc.) or null if there is no sibling element. If the function is supported by the browser (e.g. FireFox) the native implementation is used. In other browsers (e.g. Internet Explorer) it is computed here.
Name Type Description
element DomElement
Returns:
Type Description
Element The element immediately following the specified element or null if there is no such element.

staticbcdui.util.xml.parseDocument(doc)

util/xmlPackage.js, line 245
Parses an XML document and register well-known namespaces and their prefixes to enable xPath lookups thru JS API, i.e. document.selectSingleNode("/wrs:Wrs/wrs:Header").
Name Type Description
doc string | DomDocument | DomElement | DomAttribute XML Document as a String or Document or Node. If a document or a node is provided, they are cloned. A node is re-built as a document.
Returns:
wrapped Document with namespace resolver and .selectSingleNode(), .selectNodes() API

staticbcdui.util.xml.quoteXMLString(xmlString){string}

util/xmlPackage.js, line 32
Replaces the XML control characters in the specified string with the appropriate pre-defined entities.
Name Type Description
xmlString string The string to be processed.
Returns:
Type Description
string The parameter with XML control characters replaced.

staticbcdui.util.xml.removeXPath(doc, path, enableWrsExtensions, removeEmptyElements){number}

util/xmlPackage.js, line 164
Removes XML elements from a DOM document. These XML elements are identified with an XPath.
Name Type Default Description
doc DomDocument | bcdui.core.DataProvider The document the XPath specified in the "path" argument is evaluated on.
path writableModelXPath | String The XPath pointing to the nodes to be removed.
enableWrsExtensions boolean true optional Set this flag to "true" if the function should treat wrs elements differently (like converting wrs:R to wrs:D instead of removing it). It is "true" by default.
removeEmptyElements boolean false optional A flag indicating if elements which do not contain any content anymore should be removed. The default value is "false". This is for example very useful when the path is something like /Items/Item/@value and the respective Item elements need to be cleared as well.
Returns:
Type Description
number The number of removed nodes.

staticbcdui.util.xml.renameElement(element, newName){DomElement}

util/xmlPackage.js, line 123
Renames an XML element and optionally filters its child elements (which is useful in conjunction with the wrs-Format).
Name Type Description
element DomElement The XML element to be renamed.
newName string The new name of the XML element.
Returns:
Type Description
DomElement The renamed XML element.