I am reading a custom xml-file with custom tags such as <section></section> into a variable text. I then apply the following few lines of plain javascript:
parser = new DOMParser();
xmlDoc = parser.parseFromString(text, 'text/xml');
console.log(xmlDoc.documentElement);
parseDOM(xmlDoc.documentElement);
where
function parseDOM(node){
type = node.nodeName;
console.log(type);
for(child in node.children){
parseDOM(child);
}
}
The console.log(xmlDoc.documentElement) part prints out the complete hierarchy without any problems, in particular with the tags having the correct names. Unfortunately the console.log(type) part prints out "undefined" for all my custom tags.
How can I test, whether the node at hand is of the custom type
<section></section>? I was expectingnode.nodeName == 'section'to work, but apparently it does not... And while we are at it, how can I test, whether the current node is a text-block?
Thank you very much for your support.
My goal is to replace the tags (e.g. turn <section> into <h2>), but also might do some heavier alterations to some tags in the future. I know that there very likely is some library perfectly suited for the job, but I am using this project to finally to get back writing some code, so I would prefer if the solution remains within standard javascript. Again, thank you very much for your help.