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

124
Vistas
How can I put in an array all the value of HTML's element that have an 'path' as an attribute?

What I'm trying to get is an array that contains all the description value like this :

var myArray = ['First Description', 'Second Description', 'Third Description']

So, I'm doing a request to an API and I read my value like this :

const xmlDoc = new DOMParser().parseFromString(xmlStr, "application/xml");
let firstDescription = xmlDoc.evaluate('Response/QueryListResponse/DomainEntity/Property[1]/value/text()') 
console.log(firstDescription.stringValue) -- Display : First Description

But the problem with this solution is that I have only one description. So I tried to get a dom element and to navigate into it

So with this code :

x = xmlDoc.getElementsByTagName("QueryListResponse")[0];

I got a DOM element with all the values like this :

<QuerySelector>
    <MetaData></MetaData>
    <DomainEntity>
        <Property path="description">
            <Value>First Description</Value>
        </Property>
    </DomainEntity>
    <DomainEntity>
        <Property path="description">
            <Value>Second Description</Value>
        </Property>
    </DomainEntity>
    <DomainEntity>
        <Property path="description">
            <Value>Third Description</Value>
        </Property>
    </DomainEntity>
</QuerySelector>

So to get all my description I had two idea ...

The first one is to use the first solution and to use a for like this :

for (i; i <= nbOfValues; i++) {
    let v = xmlDoc.evaluate('Response/QueryListResponse/DomainEntity/Property['+i+']/value/text()') 
    myArray += v.stringValue
}

But I don't know how to find the nbOfValues .

So I think the solution of the DOM element is easier.

I think I have to do something like document.getElementByPath('description)' but it didn't work.

Any idea?

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