MCPcopy Create free account
hub / github.com/CoderLine/alphaTab / writeNode

Method writeNode

packages/alphatab/src/xml/XmlWriter.ts:23–83  ·  view source on GitHub ↗
(xml: XmlNode)

Source from the content-addressed store, hash-verified

21 }
22
23 public writeNode(xml: XmlNode) {
24 switch (xml.nodeType) {
25 case XmlNodeType.None:
26 break;
27 case XmlNodeType.Element:
28 if (this._result.length > 0) {
29 this._writeLine();
30 }
31 this._write(`<${xml.localName}`);
32 for (const [name, value] of xml.attributes) {
33 this._write(` ${name}="`);
34 this._writeAttributeValue(value);
35 this._write('"');
36 }
37
38 if (xml.childNodes.length === 0) {
39 this._write('/>');
40 } else {
41 this._write('>');
42 if (xml.childNodes.length === 1 && !xml.firstElement) {
43 this.writeNode(xml.childNodes[0]);
44 } else {
45 this._indent();
46 for (const child of xml.childNodes) {
47 // skip text nodes in case of multiple children
48 if (child.nodeType === XmlNodeType.Element || child.nodeType === XmlNodeType.Comment) {
49 this.writeNode(child);
50 }
51 }
52 this._unindend();
53 this._writeLine();
54 }
55 this._write(`</${xml.localName}>`);
56 }
57 break;
58 case XmlNodeType.Text:
59 if (xml.value) {
60 this._write(xml.value);
61 }
62 break;
63 case XmlNodeType.CDATA:
64 if (xml.value !== null) {
65 this._write(`<![CDATA[${xml.value}]]>`);
66 }
67 break;
68 case XmlNodeType.Document:
69 if (this._xmlHeader) {
70 this._write('<?xml version="1.0" encoding="utf-8"?>');
71 }
72 for (const child of xml.childNodes) {
73 this.writeNode(child);
74 }
75 break;
76 case XmlNodeType.DocumentType:
77 this._write(`<!DOCTYPE ${xml.value}>`);
78 break;
79 case XmlNodeType.Comment:
80 this._write(`<!-- ${xml.value} -->`);

Callers 1

writeMethod · 0.95

Calls 5

_writeLineMethod · 0.95
_writeMethod · 0.95
_writeAttributeValueMethod · 0.95
_indentMethod · 0.95
_unindendMethod · 0.95

Tested by

no test coverage detected