XmlNodes
MMO\core\helpers · 1 symbol · generated 5 Oct 2026
XmlNodes
XmlNodes.php:24A lightweight, mutable DOM-like tree: a list of "child nodes" that are each either a plain string (text) or another XmlNodes/XmlNode instance. XmlNodes itself is an unnamed container (a document fragment / root document); XmlNode adds a tag name and attributes on top, for an actual element. Children can be indexed numerically ($nodes[0]) or by an optional string alias ($nodes['greeting']) assigned via
- Namespace
MMO\core\helpers- Implements
- iArray, iRenderable
- Uses traits
- tPropertyGetter
- See
add/push.
Index
| alias | ||
| childNodes | ||
| ClosingTags static | HTML void elements: self-closing, never get a separate closing tag when rendered. | |
| parentNode | ||
| add($value, $alias, $first) | Add value as a node Convert any array into a HTMLNodes | |
| addXml($xml) | Parse xml and add nodes | |
| children() | ||
| clear() | Remove every child (and alias), detaching each from this tree. | |
| contains($node) | ||
| count() | \Countable::count | |
| create($tag, $attrs, $nodes) | Convenience factory: build a new node (not yet attached to this tree). | |
| debugName() | ||
| From($xml, $simplify) static | Parse XML/HTML text (or a stream) into a tree. | |
| FromFile($filename, $simplify) static | Same as From, reading the XML/HTML from a file. | |
| getAlias($node) | ||
| getContent() | ||
| getElementByTagName($tag, $ns) | Get first element with the given tag | |
| getElementsById($id) | ||
| getElementsByTagName($tag, $ns) | ||
| getIterator() | \IteratorAggregate::getIterator | |
| getParentNode() | ||
| getRootNode() | ||
| hasChildNodes() | ||
| hasElement($tag) | ||
| innerNodes($opts) | ||
| innerText() | ||
| isClosingTag($tag) | ||
| jsonSerialize() | ||
| listElementsByTagName($tags, $nodes) | Like getElementsByTagName but for several tag names at once. | |
| loopElementsByTagName($tag, $ns) | Look for all children recursively who have a given tag | |
| nearest($tags) | Walk up the ancestor chain (starting at the parent, all the way up to and including the document root) looking for the first one whose tag matches. | |
| offsetExists($key) | \ArrayAccess::offsetExists | |
| offsetGet($key) | \ArrayAccess::offsetGet -- a numeric key indexes $childNodes directly; anything else looks up $alias. | |
| offsetSet($key, $value) | \ArrayAccess::offsetSet -- setting an existing numeric index replaces that child (or, for an XmlNodes target, sets its content); an unknown key (numeric or alias) adds a new child instead. | |
| offsetUnset($key) | \ArrayAccess::offsetUnset | |
| push($key, $value) | Push a value into an EXISTING child (by numeric index or alias) -- delegates to that child's own add (or, for two adjacent text nodes, string concatenation) -- or, if $key doesn't resolve to a… | |
| remove() | Detach this node from its parent (a no-op if it has none). | |
| removeChild($node) | Detach $node from this tree's direct children (and any alias pointing at it). | |
| render($opts) | ||
| replaceChild($newNode, $oldNode) | Replace $oldNode (a direct child) with $newNode in place, carrying over any alias that pointed to $oldNode (checked up the WHOLE ancestor chain, not just this node). | |
| setAlias($alias, $node) | Name (or rename) a child so it can be looked up via $nodes['alias'] -- does NOT add $node as a child itself, see add for that. | |
| setContent($content) | Replace every child with $content (via clear then add). | |
| setParentNode($parent) | Attach this node to $parent, detaching it from its previous parent first if it had a different one. | |
| stripTags($includes, $excludes) | ||
| toArray() | ||
| __construct($nodes) | ||
| __get($key) | __get -- allow read access to a protected/private property from outside the class. | |
| __isset($key) | __isset | |
| __toString() |
Properties4
alias
- Type
- array
childNodes
- Type
- array
ClosingTags
staticHTML void elements: self-closing, never get a separate closing tag when rendered.
parentNode
Methods45
add($value, $alias, $first)
XmlNodes.php:173Add value as a node Convert any array into a HTMLNodes
| $value | mixed | anything that can be rendered by the printer -- an array (recursively added, its own keys becoming aliases), a string (merged into an adjacent text node instead of creating a new one, when possible), or any XmlNodes/XmlNode instance |
| $alias = null | null | string | if given, the new node can also be looked up via $this[$alias] afterward |
| $first = false | bool | if true, prepend instead of append |
| returns |
addXml($xml)
XmlNodes.php:267Parse xml and add nodes
| $xml | ||
| returns | void |
children()
XmlNodes.php:476| returns | array |
clear()
XmlNodes.php:204Remove every child (and alias), detaching each from this tree.
| returns | void |
contains($node)
XmlNodes.php:440count()
XmlNodes.php:545\Countable::count
| returns | int |
create($tag, $attrs, $nodes)
XmlNodes.php:110Convenience factory: build a new node (not yet attached to this tree).
debugName()
XmlNodes.php:46| returns | string | e.g. 'xmlNodes(3)' |
From($xml, $simplify)
staticXmlNodes.php:63Parse XML/HTML text (or a stream) into a tree.
| $xml | ||
| $simplify = true | bool | if true, and the parsed result has exactly one child, return that child directly instead of the wrapping XmlNodes container |
| returns | self |
FromFile($filename, $simplify)
staticXmlNodes.php:75Same as From, reading the XML/HTML from a file.
getAlias($node)
XmlNodes.php:140getContent()
XmlNodes.php:147getElementByTagName($tag, $ns)
XmlNodes.php:342Get first element with the given tag
getElementsById($id)
XmlNodes.php:382getElementsByTagName($tag, $ns)
XmlNodes.php:332| $tag | string | |
| $ns = null | null | string | |
| returns | array | all matching descendants, see loopElementsByTagName |
getIterator()
XmlNodes.php:559\IteratorAggregate::getIterator
| returns | Traversable |
getParentNode()
XmlNodes.php:258getRootNode()
XmlNodes.php:445| returns | self | the outermost ancestor -- $this itself if it has no parent |
hasChildNodes()
XmlNodes.php:393| returns | bool | true if this node has at least one child |
hasElement($tag)
XmlNodes.php:353innerNodes($opts)
XmlNodes.php:115innerText()
XmlNodes.php:120| returns | string | every text node, recursively, concatenated (tags stripped, text kept) |
isClosingTag($tag)
XmlNodes.php:80| $tag | string | |
| returns | bool | true if $tag is a self-closing/void HTML element ($ClosingTags) |
jsonSerialize()
XmlNodes.php:85listElementsByTagName($tags, $nodes)
XmlNodes.php:368Like getElementsByTagName but for several tag names at once.
loopElementsByTagName($tag, $ns)
XmlNodes.php:316Look for all children recursively who have a given tag
nearest($tags)
XmlNodes.php:458Walk up the ancestor chain (starting at the parent, all the way up to and including the document root) looking for the first one whose tag matches. See also XmlNode::closest (same intent, walked from an element rather than a fragment).
offsetExists($key)
XmlNodes.php:552\ArrayAccess::offsetExists
offsetGet($key)
XmlNodes.php:494\ArrayAccess::offsetGet -- a numeric key indexes $childNodes directly; anything else looks up $alias.
offsetSet($key, $value)
XmlNodes.php:507\ArrayAccess::offsetSet -- setting an existing numeric index replaces that child (or, for an XmlNodes target, sets its content); an unknown key (numeric or alias) adds a new child instead.
offsetUnset($key)
XmlNodes.php:531\ArrayAccess::offsetUnset
push($key, $value)
XmlNodes.php:223Push a value into an EXISTING child (by numeric index or alias) -- delegates to that child's own add (or, for two adjacent text nodes, string concatenation) -- or, if $key doesn't resolve to an existing child, falls back to add-ing $value as a brand new child.
remove()
XmlNodes.php:275Detach this node from its parent (a no-op if it has none).
| returns | self | $this, for chaining |
removeChild($node)
XmlNodes.php:402Detach $node from this tree's direct children (and any alias pointing at it).
render($opts)
XmlNodes.php:97replaceChild($newNode, $oldNode)
XmlNodes.php:420Replace $oldNode (a direct child) with $newNode in place, carrying over any alias that pointed to $oldNode (checked up the WHOLE ancestor chain, not just this node).
| $newNode | ||
| $oldNode | ||
| returns | $oldNode (now detached) | |
| throws | if $oldNode is not a direct child of this node |
setAlias($alias, $node)
XmlNodes.php:135Name (or rename) a child so it can be looked up via $nodes['alias'] -- does NOT add $node as a child itself, see add for that.
setContent($content)
XmlNodes.php:156Replace every child with $content (via clear then add).
setParentNode($parent)
XmlNodes.php:247Attach this node to $parent, detaching it from its previous parent first if it had a different one.
stripTags($includes, $excludes)
XmlNodes.php:293toArray()
XmlNodes.php:51| returns | array | the raw child nodes (strings and/or XmlNodes/XmlNode instances), in order |
__construct($nodes)
XmlNodes.php:41__get($key)
tPropertyGetter.php:25__get -- allow read access to a protected/private property from outside the class.
| $key | ||
| returns | ||
| throws | if no such property exists at all (a declared-but-uninitialized typed property is returned as-is here, and would raise PHP's own "must not be accessed before initialization" error, not this exception) |
__isset($key)
tPropertyGetter.php:36__isset
| $key | ||
| returns |