type

XElem

src @Js
class XElem : XNode

Models an XML element: its name, attributes, and children nodes.

constructors

make

Construct an element with unqualified local name and optional XML namespace.

fields

line

Line number of XML element in source file or zero if unknown.

name

Unqualified local name of the element.

ns

The XML namespace which qualified this element's name.

methods

add

If child is a XAttr then add an attribute.

addAttr

Add an attribute to this element.

attr

Get an attribute by its non-qualified local name.

attrs

Get this element's attributes as a readonly list.

children

Get this element's children elements, text, and PIs as a readonly list.

clearAttrs

Remove all the attributes.

copy

Make a shallow copy of this element.

each

Iterate each child element, text, and PI node in the children list.

eachAttr

Iterate each attribute in the attrs list.

elem

Find an element by its non-qualified local name.

elems

Get the children elements.

get

Get an attribute value by its non-qualified local name.

nodeType

Return the XNodeType.elem.

prefix

If this element is qualified by an XML namespace then return the namespace's prefix.

qname

Qualified name of the element.

remove

Remove the child element, text, or PI from this element.

removeAt

Remove the child element, text, or PI at the specified index into children.

removeAttr

Remove the attribute from this element.

removeAttrAt

Remove the attribute at the specified index into attrs.

text

Return this element's child text node.

toStr

String representation is as a start tag.

uri

If this element is qualified by an XML namespace then return the namespace's uri.

write

Write this node to the output stream.

Slot Details

add

src @Operator
This add(Obj child)

If child is a XAttr then add an attribute. Otherwise it must be a XElem, XText, or XPi and is added a child node. If the child node is already parented, then throw ArgErr. Return this.

addAttr

src This addAttr(Str name, Str val, XNs? ns := null)

Add an attribute to this element. Return this. This method is a convenience for:

add(XAttr(name, val, ns))

attr

src XAttr? attr(Str name, Bool checked := true)

Get an attribute by its non-qualified local name. If the attribute is not found and checked is false then return null otherwise throw XErr.

attrs

src XAttr[] attrs()

Get this element's attributes as a readonly list.

children

src XNode[] children()

Get this element's children elements, text, and PIs as a readonly list.

clearAttrs

src This clearAttrs()

Remove all the attributes. Return this.

copy

src This copy()

Make a shallow copy of this element.

each

src Void each(|XNode,Int| f)

Iterate each child element, text, and PI node in the children list.

eachAttr

src Void eachAttr(|XAttr,Int| f)

Iterate each attribute in the attrs list.

elem

src XElem? elem(Str name, Bool checked := true)

Find an element by its non-qualified local name. If there are multiple child elements with the name, then the first one is returned. If the element is not found and checked is false then return null otherwise throw XErr.

elems

src XElem[] elems()

Get the children elements. If this element contains text or PI nodes, then they are excluded in the result.

get

src @Operator
Str? get(Str name, Bool checked := true)

Get an attribute value by its non-qualified local name. If the attribute is not found and checked is false then return null otherwise throw XErr.

line

src Int line

Line number of XML element in source file or zero if unknown.

make

src new make(Str name, XNs? ns := null)

Construct an element with unqualified local name and optional XML namespace. The XNs instance should be defined as an attribute on this or an ancestor element (see XAttr.makeNs).

name

src Str name

Unqualified local name of the element. If an XML namespace prefix was specified, then this is everything after the colon:

<foo>    =>  foo
<x:foo>  =>  foo

nodeType

src virtual override XNodeType nodeType()

Return the XNodeType.elem. Note that during pull parsing XParser will return elemStart and elemEnd.

ns

src XNs? ns

The XML namespace which qualified this element's name. If the element name is unqualified return null.

prefix

src Str? prefix()

If this element is qualified by an XML namespace then return the namespace's prefix. Otherwise return null. If the namespace is the default namespace then prefix is "".

qname

src Str qname()

Qualified name of the element. This is the full name including the XML namespace prefix:

<foo>    =>  foo
<x:foo>  =>  x:foo

remove

src XNode? remove(XNode child)

Remove the child element, text, or PI from this element. The child is matched by reference, so you must pass in the same XNode contained by this element. Return the removed node or null if no match.

removeAt

src XNode removeAt(Int index)

Remove the child element, text, or PI at the specified index into children. Return the removed node.

removeAttr

src XAttr? removeAttr(XAttr attr)

Remove the attribute from this element. The attribute is matched by reference, so you must pass in the same XAttr contained by this element. Return the removed attribute or null if no match.

removeAttrAt

src XAttr removeAttrAt(Int index)

Remove the attribute at the specified index into attrs. Return the removed attribute.

text

src XText? text()

Return this element's child text node. If this element contains multiple text nodes then return the first one. If this element does not contain a text node return null.

toStr

src virtual override Str toStr()

String representation is as a start tag.

uri

src Uri? uri()

If this element is qualified by an XML namespace then return the namespace's uri. Otherwise return null.

write

src virtual override Void write(OutStream out)

Write this node to the output stream.