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 8559605
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T16:05:31+00:00 2026-06-11T16:05:31+00:00

I`m trying to get the attribute value of a xml by comparing it to

  • 0

I`m trying to get the attribute value of a xml by comparing it to another xml,as follows:

xmlData1 variable has xml like—>

<Root>
  <RNA A="100" x="table1" y="car11"/>
  <RNA A="101" x="table2" y="car12"/>
  <RNA A="102" x="table3" y="car13"/>
  <RNA A="103" x="table4" y="car14"/>
  <RNA A="104" x="table5" y="car15"/>
  <RNA A="105" x="table6" y="car16"/>
  <RNA A="106" x="table7" y="car17"/>
  <RNA A="107" x="table8" y="car18"/>
  <RNA A="108" x="table9" y="car19"/>
</Root>

xmlData2 variable has xml like —>

<Ina>
  <RNA B="100" x="table1" y="car11"/>
  <RNA B="101" x="table2" y="car12"/>
  <RNA B="102" x="table3" y="car13"/>
</Ina>

Here i `ve to compare like

if(xmlData1.getAttribute(x)==xmlData2.getAttribute(x) then
//code goes

How to achive this???please help

  • 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-11T16:05:33+00:00Added an answer on June 11, 2026 at 4:05 pm

    It’s reasonable simple. First off, you parse the xml. I’ve put together a X-browser function that fits your needs rather well, actually. You can find it here
    Uncomment this line:

    keep.push(parsed);//last element of array is the full DOM
    

    Just call it like so:

    var data1 = parseXML(xml1,'RNA','x');//xml1 is the first xml string
    var data2 = parseXML(xml2,'RNA','x');//xml2 === second xml string
    var xml1Parsed = data1.splice(-1);//assign document to variable
    var xml2Parsed = data2.splice(-1);
    //get the nodes of intrest
    var RNA1 = xml1Parsed.getElementsByTagName('RNA');
    var RNA2 = xml2Parsed.getElementsByTagName('RNA');
    

    both data1 and data2 are now arrays, just iterate over them:

    for (var i=0;i<data1.length;i++)
    {
        if (data1[i] === data2[i])//attribute x is the same
        {//check whatever you need
            if (RNA1[i].getAttribute('y') === RNA2[i].getAttribute('y'))
            {
                console.log('node ' + i + ' is alike');//do stuff
            }
        }
    }
    

    Just for completeness and clarity, this is the function as used in this example:

    var parseXML = (function(w,undefined)
    {
        'use strict';
        var parser,i,ie,parsed;
        ie = false;
        switch (true)
        {
            case w.DOMParser !== undefined:
                parser = new w.DOMParser();
            break;
            case new w.ActiveXObject("Microsoft.XMLDOM") !== undefined:
                parser = new w.ActiveXObject("Microsoft.XMLDOM");
                parser.async = false;
                ie = true;
            break;
            default :
                throw new Error('No parser found');
        }
        return function(xmlString,getTags,getAttr)
        {
            var tags,keep = [];
            if (ie === true)
            {
                parser.loadXML(xmlString);
                parsed = parser;
            }
            else
            {
                parsed = parser.parseFromString(xmlString,'text/xml');
            }
            tags = parsed.getElementsByTagName(getTags);
            for(i=0;i<tags.length;i++)
            {
                if (!getAttr || getAttr === 'textContent')
                {
                    keep.push(tags[i].textContent);
                    continue;
                }
                if (getAttr && tags[i].getAttribute(getAttr))
                {
                    keep.push(tags[i].getAttribute(getAttr));
                }
            }
            keep.push(parsed);//last element of array is the full DOM
            return keep;
        }
    })(this);//assuming global declaration, if not: replace with window
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to get the value of an attribute full where another attribute
I'm trying to get the value of attribute(memo) in an xml file using c#,also
I am trying to get an attribute value from an XML file, but my
I trying to get all attribute values from xml file where value doesn't start
My XML is structured like the example below. I'm trying to get the attribute
I'm trying to get XPath to return an attribute value yet first search for
I'm trying to compare one attribute value to another, if it returns true i
I'm trying to get a collection of values from an XML document: <root> <string
I've got a xml file that looks like this and I'm trying to get
How do I get the attribute value of an XML node with Javascript /

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.