Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

138
Vistas
How to access tagName of custom node in DOM

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 expecting node.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.

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda