Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8146181
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:54:37+00:00 2026-06-06T13:54:37+00:00

Is it possible to access an XML section / node using an attribute value

  • 0

Is it possible to access an XML section / node using an attribute value (e.g. id) using JavaScript?

For example:

<people>
    <person id='1'>
        <name>Tom</name>
        <age>30</age>
    </person>
    <person id='2'>
        <name>Ian</name>
        <age>22</age>
    </person>
    <person id='3'>
        <name>Ben</name>
        <age>45</age>
    </person>
</people>

I want to be able to select a person with a given id. For example, finding the ID 2 would return Ian.

This is possible in ActionScript like so:

xml.people.person.(@id == 2).name

Is something similar available in JS?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T13:54:40+00:00Added an answer on June 6, 2026 at 1:54 pm

    Assuming you have an XMLDocument, the only cross-browser way is to loop through the nodes:

    var people = doc.getElementsByTagName('person');
    
    for(var i = 0; i < people.length; i++) {
        if(people[i].getAttribute('id') === '2') {
            // Found it!
        }
    }
    

    If you need to do very complicated expressions, however, it may be worth it to use XPath, even though it needs a bit of cross-browser checking.

    Here’s the standard way:

    document.evaluate('//person[@id='2']/text()[0]', doc.documentElement, null, XPathResult.STRING_TYPE, null).stringValue;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to access a node of Xml using an arbitary path? Eg:
Does it possible to access microphone or Webcam using Visual Basic Scripting ? i
Is it possible to access value of a global variable declared, in another perl
Is is possible to access the value that is in a selectOneMenu through FacesContext?
Given this sample XML data, is it possible to access a Key directly? eg:
I know that I can access an XML Element with tag name 'page' like
Is it possible to access child node attributes in xsl:if I have to convert
Is it possible to access content of user settings.xml file from a maven plugin
Is it possible to access digg's API from Flash without using a proxy to
I'm trying to make it possible to access/upload documents to Alfresco using shared drive,

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.