XmlNode
MMO\core\helpers · 1 symbol · generated 5 Oct 2026
XmlNode
XmlNode.php:18An XmlNodes with a tag name and attributes -- an actual XML/HTML element. Attribute access supports an optional namespace prefix, and can also go through array access using an '@'-prefixed key ($node['@class'] reads/writes the 'class' attribute, alongside $node[0] etc. for children).
- Namespace
MMO\core\helpers- Extends
- XmlNodes
- Todo
- replace property getter with actual public properties
Index
| attributes | ||
| tagName | ||
| addCSSClass($class) | Add one or more (space-separated) classes to the 'class' attribute, without duplicating ones already present. | |
| closest($tag) | 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 $tag. | |
| debugName() | ||
| From($xml, $simplify) static | ||
| getAttribute($name, $ns) | ||
| getAttributes() | ||
| hasAttribute($name, $ns) | ||
| hasCSSClass($class) | ||
| isSelfClosing() | ||
| IsValidTag($tag) static | ||
| nextElementSibling() | ||
| nextSibling() | ||
| offsetExists($key) | \ArrayAccess::offsetExists -- a '@name' key checks that attribute; anything else falls through to | |
| offsetGet($key) | \ArrayAccess::offsetGet -- a '@name' key reads that attribute; anything else falls through to | |
| offsetSet($key, $value) | \ArrayAccess::offsetSet -- a '@name' key sets that attribute; anything else falls through to | |
| offsetUnset($key) | \ArrayAccess::offsetUnset -- a '@name' key removes that attribute; anything else falls through to | |
| removeAttribute($name) | ||
| removeCSSClass($class) | ||
| render($opts) | ||
| renderTag() | ||
| setAttribute($key, $value) | Set attribute | |
| setAttributes($attrs) | Set several attributes at once (each via setAttribute). | |
| toArray() | ||
| __construct($tag, $attrs, $nodes) |
Properties2
attributes
- Type
- array
tagName
- Type
- string
Methods24
addCSSClass($class)
XmlNode.php:200Add one or more (space-separated) classes to the 'class' attribute, without duplicating ones already present.
| $class | string | |
| returns |
closest($tag)
XmlNode.php:66Walk 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 $tag.
debugName()
XmlNode.php:47| returns | string | e.g. 'xmlNode(div)' |
From($xml, $simplify)
staticXmlNode.php:37| $xml | ||
| $simplify = true | bool | |
| returns | self | |
| throws | always -- parsing produces a whole tree (possibly several elements), not a single pre-tagged XmlNode; use XmlNodes::From instead |
getAttribute($name, $ns)
XmlNode.php:125getAttributes()
XmlNode.php:139| returns | array | every attribute, name => value |
hasAttribute($name, $ns)
XmlNode.php:107hasCSSClass($class)
XmlNode.php:188isSelfClosing()
XmlNode.php:180| returns | bool | true if this tag is a self-closing/void HTML element (XmlNodes::$ClosingTags) |
IsValidTag($tag)
staticXmlNode.php:42nextElementSibling()
XmlNode.php:82nextSibling()
XmlNode.php:74| returns | mixed | the next sibling (a string or an XmlNodes/XmlNode instance), or null if this is the last child |
offsetExists($key)
XmlNode.php:270\ArrayAccess::offsetExists -- a '@name' key checks that attribute; anything else falls through to
- See
XmlNodes::offsetExistsfor children.
offsetGet($key)
XmlNode.php:246\ArrayAccess::offsetGet -- a '@name' key reads that attribute; anything else falls through to
- See
XmlNodes::offsetGetfor children. Returned by reference (so e.g.$node['@class'][] = 'box';can mutate an array-valued attribute in place) -- for an attribute that isn't set, this returns a reference to a fresh, unsharednullinstead of indexing$attributesdirectly: doing the latter would have PHP silently auto-vivify that key (creating a real, permanentnull-valued attribute as a side effect of merely reading it) -- which then renders as a stray bare attribute, sincesetAttributetreats anullvalue as one.
offsetSet($key, $value)
XmlNode.php:260\ArrayAccess::offsetSet -- a '@name' key sets that attribute; anything else falls through to
- See
XmlNodes::offsetSetfor children.
offsetUnset($key)
XmlNode.php:231\ArrayAccess::offsetUnset -- a '@name' key removes that attribute; anything else falls through to
- See
XmlNodes::offsetUnsetfor children.
removeAttribute($name)
XmlNode.php:144removeCSSClass($class)
XmlNode.php:212render($opts)
XmlNode.php:174| $opts = [] | array | |
| returns | string | the full element: opening tag, rendered children, and closing tag (unless isSelfClosing) |
renderTag()
XmlNode.php:159| returns | string | the opening tag, e.g. '<div class="box">' or '<br />' if isSelfClosing |
setAttribute($key, $value)
XmlNode.php:154Set attribute
setAttributes($attrs)
XmlNode.php:95Set several attributes at once (each via setAttribute).
toArray()
XmlNode.php:52| returns | array | same as XmlNodes::toArray, plus '<' (the tag name) and '@' (the attributes) |
__construct($tag, $attrs, $nodes)
XmlNode.php:27| $tag | ||
| $attrs = [] | name => value | |
| $nodes = [] | initial children, see XmlNodes::add |
Inherited members (40)
| Properties | Declared by | Description | |
|---|---|---|---|
alias | XmlNodes | ||
childNodes | XmlNodes | ||
ClosingTags | XmlNodes | HTML void elements: self-closing, never get a separate closing tag when rendered. | |
parentNode | XmlNodes |
| Methods | Declared by | Description | |
|---|---|---|---|
add($value, $alias, $first) | XmlNodes | Add value as a node Convert any array into a HTMLNodes | |
addXml($xml) | XmlNodes | Parse xml and add nodes | |
children() | XmlNodes | ||
clear() | XmlNodes | Remove every child (and alias), detaching each from this tree. | |
contains($node) | XmlNodes | ||
count() | XmlNodes | \Countable::count | |
create($tag, $attrs, $nodes) | XmlNodes | Convenience factory: build a new node (not yet attached to this tree). | |
FromFile($filename, $simplify) | XmlNodes | Same as From, reading the XML/HTML from a file. | |
getAlias($node) | XmlNodes | ||
getContent() | XmlNodes | ||
getElementByTagName($tag, $ns) | XmlNodes | Get first element with the given tag | |
getElementsById($id) | XmlNodes | ||
getElementsByTagName($tag, $ns) | XmlNodes | ||
getIterator() | XmlNodes | \IteratorAggregate::getIterator | |
getParentNode() | XmlNodes | ||
getRootNode() | XmlNodes | ||
hasChildNodes() | XmlNodes | ||
hasElement($tag) | XmlNodes | ||
innerNodes($opts) | XmlNodes | ||
innerText() | XmlNodes | ||
isClosingTag($tag) | XmlNodes | ||
jsonSerialize() | XmlNodes | ||
listElementsByTagName($tags, $nodes) | XmlNodes | Like getElementsByTagName but for several tag names at once. | |
loopElementsByTagName($tag, $ns) | XmlNodes | Look for all children recursively who have a given tag | |
nearest($tags) | XmlNodes | 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. | |
push($key, $value) | XmlNodes | 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() | XmlNodes | Detach this node from its parent (a no-op if it has none). | |
removeChild($node) | XmlNodes | Detach $node from this tree's direct children (and any alias pointing at it). | |
replaceChild($newNode, $oldNode) | XmlNodes | 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) | XmlNodes | 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) | XmlNodes | Replace every child with $content (via clear then add). | |
setParentNode($parent) | XmlNodes | Attach this node to $parent, detaching it from its previous parent first if it had a different one. | |
stripTags($includes, $excludes) | XmlNodes | ||
__get($key) | XmlNodes | __get -- allow read access to a protected/private property from outside the class. | |
__isset($key) | XmlNodes | __isset | |
__toString() | XmlNodes |