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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:17:06+00:00 2026-05-24T17:17:06+00:00

I’m wondering if anyone knows how to do this: I have an XML tree

  • 0

I’m wondering if anyone knows how to do this: I have an XML tree like this – I have added the numbers in the order they should appear, but this needs to be dynamic:

<scene id="1>
  <scene id="2>
    <scene id="3"/>
  </scene>
  <scene id="4>
<scene id="5>
<scene id="6>

Where there are 3 parent scenes, and any number of children and subchildren for each of the three parents. Each of the three scenes will be assigned its own sprite image for use representing an icon for each scene, and all of its children will use its the parent sprite, but I need to figure out a system to assign the sprite the proper background position based on where it is in the tree. So what I need to do is say:

Each root sprite is at 0px horizontal. The first child is at (1*80px). The second child is at 2*80px. The first subchild is at whatever the last child was at, plus 80px.

So essentially I need to assign logical numbers to each node in this sequence. How would I do this mathematically? I’m using javascript (jquery) to parse the XML.

Thanks for any ideas you can come up with.

  • 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-24T17:17:08+00:00Added an answer on May 24, 2026 at 5:17 pm

    Assuming you are using jQuery 1.5+ and you’ve got a well formed, valid XML document (i.e. with a root element) you could do something like this:

    var nextId = 1;
    var xmlStr = '<movie>' +
                 '  <scene>' + // id1
                 '    <scene>' + // id2
                 '      <scene/>' + // id3
                 '    </scene>' +
                 '    <scene/>' + // id4
                 '  </scene>' +
                 '  <scene/>' + // id5
                 '</movie>';
    var doc = $(xmlStr);
    $(doc).find('scene').each(function(i, el) {
      el.id = ("id" + nextId++);
    });
    

    Note that valid “id” attributes must not start with a digit, hence the new values “id1”, etc. The resulting doc should have each “scene” element with the incremented “id” value.

    doc;
    // <movie>​
    //   <scene id=​"id1">​
    //     <scene id=​"id2">​
    //       <scene id=​"id3">​</scene>​
    //     </scene>​
    //     <scene id=​"id4">​</scene>​
    //   </scene>​
    //   <scene id=​"id5">​</scene>​
    // </movie>​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have some data like this: 1 2 3 4 5 9 2 6
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I have this code to decode numeric html entities to the UTF8 equivalent character.
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Does anyone know how can I replace this 2 symbol below from the string
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and

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.