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
XMLfor the body element.- Returns:
XML.
EXAMPLE
var result = xml.body();
- documentElement()¶
Return an
XMLfor 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
XMLyet.- Arguments:
tag –
String.
- 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
XMLyet.- Arguments:
text –
String.
- Returns:
XML.
EXAMPLE
var result = xml.createElement("Hello world!");
- find(tag, attribute, value)¶
Find the element matching the
tag,attributeandvalue. Set either of those tonullto match anything.- Arguments:
tag –
String.attribute –
String.value –
String.
- Returns:
XML.
EXAMPLE
var result = xml.find("tag", "attribute", "value");
- findNext(tag, attribute, value)¶
Find the next element matching the
tag,attributeandvalue. Set either of those tonullto match anything.- Arguments:
tag –
String.attribute –
String.value –
String.
- 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:
dom –
XML.childDom –
XML.
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:
dom –
XML.elementDom –
XML.
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:
dom –
XML.elementDom –
XML.
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, ornullif no child exist.- Returns:
XML|null.
EXAMPLE
var result = xml.firstChild();
- parent()¶
Return the parent of the element as a
XML, ornullif no parent exists.- Returns:
XML|null.
EXAMPLE
var result = xml.parent();
- next()¶
Return the next element as a
XML, ornullif no such element exists.- Returns:
XML|null.
EXAMPLE
var result = xml.next();
- previous()¶
Return the previous element as a
XML, ornullif 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:
attribute –
String.value –
String.
- Returns:
XML.
EXAMPLE
var result = xml.addAttribute("attribute", "value");
- removeAttribute(attribute)¶
Remove the specified attribute from the element.
- Arguments:
attribute –
String.
EXAMPLE
xml.removeAttribute("attribute");
- attribute(attribute)¶
Return the element’s attribute value as a
String, ornullif no such attribute exists.- Arguments:
attribute –
String.
- 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();