Documentation / @sw-file-lib/xml / SwXmlNode
Class: SwXmlNode
class SwXmlNode extends SwXmlNodeList {
constructor(tag: string, attrs: Map<string, string>, children: SwXmlNode[]);
nodes: SwXmlNode[];
readonly tag: string;
readonly attrs: Map<string, string>;
asNodeList(): SwXmlNode[];
countChild(tag?: string): number;
child(tag: string): { index: number; value: SwXmlNode } | undefined;
firstChild(tag: string): { index: number; value: SwXmlNode } | undefined;
lastChild(tag: string): { index: number; value: SwXmlNode } | undefined;
selectChild(tag: string, duplicateChildElement?: DuplicateChildElementMode): { index: number; value: SwXmlNode } | undefined;
childTags(): string[];
attr(name: string): string | undefined;
setAttr(name: string, value: string): void;
}Defined in: packages/xml/src/parser/xmlNode.ts:111
A parsed Stormworks XML element.
Extends
Constructors
Constructor
new SwXmlNode(
tag: string,
attrs: Map<string, string>,
children: SwXmlNode[]): SwXmlNode;Defined in: packages/xml/src/parser/xmlNode.ts:112
Parameters
| Parameter | Type |
|---|---|
tag | string |
attrs | Map<string, string> |
children | SwXmlNode[] |
Returns
SwXmlNode
Overrides
Properties
nodes
nodes: SwXmlNode[];Defined in: packages/xml/src/parser/xmlNode.ts:12
Inherited from
tag
readonly tag: string;Defined in: packages/xml/src/parser/xmlNode.ts:113
attrs
readonly attrs: Map<string, string>;Defined in: packages/xml/src/parser/xmlNode.ts:114
Methods
asNodeList()
asNodeList(): SwXmlNode[];Defined in: packages/xml/src/parser/xmlNode.ts:17
Returns the nodes as a list and requires all child tags to be the same.
Returns
SwXmlNode[]
Inherited from
countChild()
countChild(tag?: string): number;Defined in: packages/xml/src/parser/xmlNode.ts:32
Returns the number of child node. If a tag name is given, only children that have the same tag name counts.
Parameters
| Parameter | Type |
|---|---|
tag? | string |
Returns
number
Inherited from
child()
child(tag: string):
| {
index: number;
value: SwXmlNode;
}
| undefined;Defined in: packages/xml/src/parser/xmlNode.ts:49
Returns a unique child node and its index by tag name.
Parameters
| Parameter | Type |
|---|---|
tag | string |
Returns
| { index: number; value: SwXmlNode; } | undefined
Inherited from
firstChild()
firstChild(tag: string):
| {
index: number;
value: SwXmlNode;
}
| undefined;Defined in: packages/xml/src/parser/xmlNode.ts:66
Returns the first child node and its index with the given tag name.
Parameters
| Parameter | Type |
|---|---|
tag | string |
Returns
| { index: number; value: SwXmlNode; } | undefined
Inherited from
lastChild()
lastChild(tag: string):
| {
index: number;
value: SwXmlNode;
}
| undefined;Defined in: packages/xml/src/parser/xmlNode.ts:77
Returns the last child node and its index with the given tag name.
Parameters
| Parameter | Type |
|---|---|
tag | string |
Returns
| { index: number; value: SwXmlNode; } | undefined
Inherited from
selectChild()
selectChild(tag: string, duplicateChildElement?: DuplicateChildElementMode):
| {
index: number;
value: SwXmlNode;
}
| undefined;Defined in: packages/xml/src/parser/xmlNode.ts:91
Selects one child node by tag name.
By default, duplicate child elements are treated as an error. Pass "first" or "last" to tolerate duplicates and choose the corresponding child.
Parameters
| Parameter | Type |
|---|---|
tag | string |
duplicateChildElement? | DuplicateChildElementMode |
Returns
| { index: number; value: SwXmlNode; } | undefined
Inherited from
childTags()
childTags(): string[];Defined in: packages/xml/src/parser/xmlNode.ts:103
Returns the unique child tag names in this node list.
Returns
string[]
Inherited from
attr()
attr(name: string): string | undefined;Defined in: packages/xml/src/parser/xmlNode.ts:123
Returns an attribute value by name.
Parameters
| Parameter | Type |
|---|---|
name | string |
Returns
string | undefined
setAttr()
setAttr(name: string, value: string): void;Defined in: packages/xml/src/parser/xmlNode.ts:130
Sets an attribute value by name.
Parameters
| Parameter | Type |
|---|---|
name | string |
value | string |
Returns
void