I'm trying to use this code to iterate over child elements, but it doesn't work. I'm expecting it to log child\ntext 9 times but it logs undefined\n\n 3 times. If I log the child variable, it logs one XmlText instance 3 times.
const xml2 = XmlDocument.fromString(`
<root>
<parent>
<parent2>
<child>text</child>
<child>text</child>
<child>text</child>
</parent2>
<parent2>
<child>text</child>
<child>text</child>
<child>text</child>
</parent2>
<parent2>
<child>text</child>
<child>text</child>
<child>text</child>
</parent2>
</parent>
</root>
`);
xml2.find("//parent").forEach(e => {
e.find("parent2").forEach(e => {
let child = e.firstChild;
while (child) {
console.log(child.name);
console.log(child.content);
child = child.nextSibling;
}
});
});
I'm trying to use this code to iterate over child elements, but it doesn't work. I'm expecting it to log
child\ntext9 times but it logsundefined\n\n3 times. If I log the child variable, it logs one XmlText instance 3 times.