Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

123
Visualizações
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 à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda