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

259
Views
get values from XML which is a string in javascript

I am trying to get values from an XML string which is like this

<ROOT>
<ADDALTERNATE>
<DATA>
<SELECTEDDATA ID="3534" NAME="sampleName" CODE="SampleCode" CODEIDS="133277,133278,133279,133280"/>
</DATA>
</ADDALTERNATE>
</ROOT>

How do I get the values from CODE tag from the given XML in javascript simplest way? tried different way it did not work .

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can use the DOMParser combined with a little XPATH to locate the required value.

const xmlStr = `<ROOT>
<ADDALTERNATE>
<DATA>
<SELECTEDDATA ID="3534" NAME="sampleName" CODE="SampleCode" CODEIDS="133277,133278,133279,133280"/>
</DATA>
</ADDALTERNATE>
</ROOT>`;

const parser = new DOMParser();
const doc = parser.parseFromString(xmlStr, "application/xml");

const code = doc.evaluate(`//SELECTEDDATA/@CODE`, doc, null, XPathResult.STRING_TYPE, null);
console.log(code.stringValue);

about 4 years ago · Juan Pablo Isaza Report
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!