Skip to content

Class: XmlElement ​

Defined in: netconf/src/xml/element.ts:81

An immutable, namespace-aware XML element: what a read resolves with by default, what x() and parseXml() build, and what an RPC sends. Names and namespaces are resolved URIs, so navigation doesn't depend on the prefixes the server chose. See Output format.

Constructors ​

Constructor ​

ts
new XmlElement(init): XmlElement;

Defined in: netconf/src/xml/element.ts:114

Parameters ​

init ​

XmlElementInit

Returns ​

XmlElement

Properties ​

attributes ​

ts
readonly attributes: readonly XmlAttribute[];

Defined in: netconf/src/xml/element.ts:93

The element's attributes, in order. Namespace declarations aren't attributes; see declarations.


children ​

ts
readonly children: readonly XmlNode[];

Defined in: netconf/src/xml/element.ts:95

Child elements and text, in document order.


declarations ​

ts
readonly declarations: ReadonlyMap<string, string>;

Defined in: netconf/src/xml/element.ts:97

Namespace declarations made on this element itself (prefix → URI; '' is the default namespace).


inScope ​

ts
readonly inScope: ReadonlyMap<string, string>;

Defined in: netconf/src/xml/element.ts:112

Every namespace declaration in scope at this element: its own and, for a parsed element, its ancestors' where it was parsed, the nearest winning. An element built with x() has only its own. Prefixes used inside values (identityrefs, instance-identifiers, XPath) resolve against this, as RFC 7950 §9.10.3 and §9.13.2 require, so they keep their meaning after the element is taken out of its document.

A parsed element's map shares its ancestors' entries rather than copying them, so read it through its methods. Code that reads a Map's storage without calling them (structuredClone, postMessage, a Map.prototype method called on it) can see it empty; copy it first with new Map(el.inScope).


name ​

ts
readonly name: string;

Defined in: netconf/src/xml/element.ts:83

Local name, without prefix.


ns ​

ts
readonly ns: string | undefined;

Defined in: netconf/src/xml/element.ts:89

Namespace URI ('' for no namespace). undefined only on an element built without one, which takes its parent's default namespace when serialised.


prefix ​

ts
readonly prefix: string | undefined;

Defined in: netconf/src/xml/element.ts:91

The prefix the element had when parsed, or the one to prefer when serialising; a hint only.

Accessors ​

elements ​

Get Signature ​

ts
get elements(): XmlElement[];

Defined in: netconf/src/xml/element.ts:142

Child elements, in document order.

Returns ​

XmlElement[]

Methods ​

[INSPECT]() ​

ts
[INSPECT](): string;

Defined in: netconf/src/xml/element.ts:208

How Node's console.log and util.inspect show the element: indented XML. An element that can't be serialised (an invalid name or character) shows its name and the reason instead of throwing.

Returns ​

string


attr() ​

ts
attr(name, ns?): string | undefined;

Defined in: netconf/src/xml/element.ts:180

Attribute value.

Parameters ​

name ​

string

ns? ​

string

Namespace of a qualified attribute. Omit for an unqualified attribute.

Returns ​

string | undefined


child() ​

ts
child(name, ns?): XmlElement | undefined;

Defined in: netconf/src/xml/element.ts:150

First child element with this local name.

Parameters ​

name ​

string

ns? ​

string

Namespace URI to match. Omit to match any namespace.

Returns ​

XmlElement | undefined


childrenNamed() ​

ts
childrenNamed(name, ns?): XmlElement[];

Defined in: netconf/src/xml/element.ts:161

All child elements with this local name, in document order.

Parameters ​

name ​

string

ns? ​

string

Namespace URI to match. Omit to match any namespace.

Returns ​

XmlElement[]


lookupNamespace() ​

ts
lookupNamespace(prefix): string | undefined;

Defined in: netconf/src/xml/element.ts:137

The namespace a prefix is bound to at this element ('' for the default namespace), or undefined if it isn't bound. The xml prefix is always bound. Named after the DOM's lookupNamespaceURI.

Parameters ​

prefix ​

string

Returns ​

string | undefined


path() ​

ts
path(path, ns?): XmlElement | undefined;

Defined in: netconf/src/xml/element.ts:169

Follow a /-separated path of local names, taking the first match at each step.

Parameters ​

path ​

string

ns? ​

string

If given, every step must be in this namespace.

Returns ​

XmlElement | undefined


text() ​

ts
text(): string;

Defined in: netconf/src/xml/element.ts:185

Concatenated character data of the direct children only.

Returns ​

string


textContent() ​

ts
textContent(): string;

Defined in: netconf/src/xml/element.ts:192

Concatenated character data of all descendants, in document order.

Returns ​

string


toString() ​

ts
toString(): string;

Defined in: netconf/src/xml/element.ts:199

The element as compact XML, the same as serializeXml(this).

Returns ​

string

Released under the MIT Licence.