XML

mutool only

This represents an HTML or an XML node. It is a helper class intended to access the DOM (Document Object Model) content of a Story object.

Instance methods

body()

Return an XML for the body element.

Returns:

XML.

EXAMPLE

var result = xml.body();
documentElement()

Return an XML for the top level element.

Returns:

XML.

EXAMPLE

var result = xml.documentElement();
createElement(tag)

Create an element with the given tag type, but do not link it into the XML yet.

Arguments:
  • tagString.

Returns:

XML.

EXAMPLE

var result = xml.createElement("div");
createTextNode(text)

Create a text node with the given text contents, but do not link it into the XML yet.

Arguments:
  • textString.

Returns:

XML.

EXAMPLE

var result = xml.createElement("Hello world!");
find(tag, attribute, value)

Find the element matching the tag, attribute and value. Set either of those to null to match anything.

Arguments:
  • tagString.

  • attributeString.

  • valueString.

Returns:

XML.

EXAMPLE

var result = xml.find("tag", "attribute", "value");
findNext(tag, attribute, value)

Find the next element matching the tag, attribute and value. Set either of those to null to match anything.

Arguments:
  • tagString.

  • attributeString.

  • valueString.

Returns:

XML.

EXAMPLE

var result = xml.findNext("tag", "attribute", "value");
appendChild(dom, childDom)

Insert an element as the last child of a parent, unlinking the child from its current position if required.

Arguments:
  • domXML.

  • childDomXML.

EXAMPLE

xml.appendChild(dom, childDom);
insertBefore(dom, elementDom)

Insert an element before this element, unlinking the new element from its current position if required.

Arguments:
  • domXML.

  • elementDomXML.

EXAMPLE

xml.insertBefore(dom, elementDom);
insertAfter(dom, elementDom)

Insert an element after this element, unlinking the new element from its current position if required.

Arguments:
  • domXML.

  • elementDomXML.

EXAMPLE

xml.insertAfter(dom, elementDom);
remove()

Remove this element from the XML. The element can be added back elsewhere if required.

Returns:

XML.

EXAMPLE

var result = xml.remove();
clone()

Clone this element (and its children). The clone is not yet linked into the XML.

Returns:

XML.

EXAMPLE

var result = xml.clone();
firstChild()

Return the first child of the element as a XML, or null if no child exist.

Returns:

XML | null.

EXAMPLE

var result = xml.firstChild();
parent()

Return the parent of the element as a XML, or null if no parent exists.

Returns:

XML | null.

EXAMPLE

var result = xml.parent();
next()

Return the next element as a XML, or null if no such element exists.

Returns:

XML | null.

EXAMPLE

var result = xml.next();
previous()

Return the previous element as a XML, or null if no such element exists.

Returns:

XML | null.

EXAMPLE

var result = xml.previous();
addAttribute(attribute, value)

Add attribute with the given value, returns the updated element as an XML.

Arguments:
  • attributeString.

  • valueString.

Returns:

XML.

EXAMPLE

var result = xml.addAttribute("attribute", "value");
removeAttribute(attribute)

Remove the specified attribute from the element.

Arguments:
  • attributeString.

EXAMPLE

xml.removeAttribute("attribute");
attribute(attribute)

Return the element’s attribute value as a String, or null if no such attribute exists.

Arguments:
  • attributeString.

Returns:

String | null.

EXAMPLE

var result = xml.attribute("attribute");
getAttributes()

Returns a dictionary object with properties and their values corresponding to the element’s attributes and their values.

Returns:

{}.

EXAMPLE

var dict = xml.getAttributes();