Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

131
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!