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

  • Home
  • SEARCH
  • 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 245341
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:04:50+00:00 2026-05-11T21:04:50+00:00

I have the following XML- <rows> <row id=5> <cell>Item1</cell> <attrs> <attr> <id>1</id> <type>CheckBox</type> <values>

  • 0

I have the following XML-

<rows>
   <row id="5">
      <cell>Item1</cell>
   <attrs>
    <attr>
      <id>1</id>
      <type>CheckBox</type>
      <values>
        <value>
          <id>10</id>
        </value>
        <value>
          <id>11</id>
        </value>
      </values>
    </attr>
     <attr>
       <id>2</id>
       <type>CheckBox</type>
       <values>
         <value>
           <id>20</id>
         </value>
         <value>
           <id>21</id>
         </value>
       </values>
     </attr>
  </attrs>
   </row>
</rows>

What I want to do is to loop each of the of a certain row.

I tried to do this in order to get all of the attr ids but I also got the values ids.

function fillForm(id){
    var theRow = $(theXmlDoc).find('row[id='+id+']').get()

    $(theRow).find("attr").each(function(i) 
    {
        alert($(this).find("id").text());
    });
}

I also would like to note that main goal is loop each attr and afterwards to loop each value while I have the attr’s id.

P.S if you think of an easier/simpler way to do so with some other library I’m open for suggestions.

Thanks in advance,

  • 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-05-11T21:04:51+00:00Added an answer on May 11, 2026 at 9:04 pm

    I’m not clear what you’re trying to loop over, I think one of the tags in your question was garbled. You say: “What I want to do is to loop each of the of a certain row.” and I think you had a tag in there.

    Anyway, here’s some examples of extracting data from the parsed xml document using jQuery. The comments show what will be alerted.

    I think part of the problem is you have the id values as siblings rather than children to the attributes. It seems like a more coherent structure might be:

    <rows>
        <row id="5">
            <cell>Item1</cell>
            <attrs>
                <attr id="1">
                    <type>CheckBox</type>
                    <values>
                        <value>
                            <id>10</id>
                        </value>
                        <value>
                            <id>11</id>
                        </value>
                    </values>
                </attr>
                <attr id="2">
                    <type>CheckBox</type>
                    <values>
                        <value>
                            <id>20</id>
                        </value>
                        <value>
                            <id>21</id>
                        </value>
                    </values>
                </attr>
            </attrs>
        </row>
    </rows>
    

    But if you don’t have control over the xml, please ignore that suggestion. 🙂

    Okay, here are some samples of traversal to get various pieces of data:

    First let’s just get “Item1”

    <script type="text/javascript">
    // Item1
    $.get('sample.xml', null, function (data, textStatus) {
        alert( $(data).find('rows row[id=5] cell').text());
    }, 'xml');
    </script>
    

    Now we’ll get the 1 and the 2:

    <script type="text/javascript">
    // 1
    // 2
    $.get('sample.xml', null, function (data, textStatus) {
        $(data).find('rows row[id=5] attrs attr > id').each( function(){
                alert($(this).text()); // 1, 2
        });
    }, 'xml');
    </script>
    

    And lastly, let’s pull out the main attr ids and tie them into the values:

    <script type="text/javascript">
    // rows row[id=5] attrs attr > id 1 has inner ids of 10,11
    // rows row[id=5] attrs attr > id 2 has inner ids of 20,21
    $.get('sample.xml', null, function (data, textStatus) {
    
            var out = ''
            $(data).find('rows row[id=5] attrs attr > id').each( function(){
                    out += 'rows row[id=5] attrs attr > id ' + $(this).text();
                    var innerIds = [];
                    $(this).siblings('values').find('value id').each(function(){
                        innerIds.push($(this).text())
                    });
                    out += ' has inner Ids of ' + innerIds.join(',') + '\n';
            });
            alert(out);
        }, 'xml');
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have the following xml (a quick example) <rows> <row> <name>one</name> </row>
I have some xml in the following format: <fileExport> <rows> <row id=0> <columns> <column
I have the following XML and I want to process it so that I
I have a loop in xsl and depending upon the attribute value, i want
I have the following XML (partial) document : <export> <table name=CLIENT> <row> <col name=CODE_CLIENT
I have the following PHP script : <?php header('Content-type: text/xml'); mysql_connect('localhost', 'root', 'root'); mysql_select_db('sportApp');
I have an XML file with the following structure: <root> <subroot id=someID> <val1 value=a/>
I have an xml document in the following format. <?xml version=1.0 encoding=UTF-8 ?> <Rows>
I have an XML structure like the following: <tables> <table name=tableName1> <row ID=34 col1=data
I have the following XML structure: <?xml version=1.0 ?> <course xml:lang=nl> <body> <item id=787900813228567

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.