• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

195
Views
xmlDoc.getElementsByTagName no es una función

Ejecutó HTML a través del servidor local para analizar un archivo de texto que está escrito en formato XML. Dentro de la función XMLHttpRequest, puedo imprimir el nodo de la variable xmlDoc que quiero. Pero luego, fuera de la función XMLHttpRequest, básicamente olvida lo que está almacenado en la variable xmlDoc .

¿Por qué no puedo sacar la salida de la variable XML xmlDoc analizada de la función XMLHttpRequest?

HTML

 <!DOCTYPE html> <html> <body> <p id="demo"></p> </body> <script> var xmlDoc = new DOMParser(); var xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { parser = new DOMParser(); xmlDoc = parser.parseFromString(this.responseText,"text/xml"); console.log(xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue) } }; xhttp.open("GET", "project_content.txt", true); xhttp.send(); console.log(xmlDoc.getElementsByTagName("title")[0].childNodes[0].nodeValue) </script> </html>

Archivo TXT

 <projects> <mini_title> COVID-19 POWER BI </mini_title> <title> COVID-19 POWER BI </title> <techniques> SQL, DAX, Micorsoft SQL Sever, and Power BI </techniques> <about> random text </about> <mini_title> FOREX ML TRADER </mini_title> <title> FOREX MACHINE LEARING AUTO TRADER </title> <techniques> Python, Object-Oriented Programming, GUI, MetaTrader 5 Python Package, and Machine Learning </techniques> <about> random text </about> </projects>

Resultado esperado (consola de Chrome):

 COVID-19 POWER BI COVID-19 POWER BI

Resultado real (consola cromada):

[tester.html:57 TypeError no detectado: xmlDoc.getElementsByTagName no es una función en tester.html:57

tester.html:51 COVID-19 POWER BI

] 1

almost 3 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error