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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:06:43+00:00 2026-05-27T20:06:43+00:00

Hi how do i retrieve the top level parent of an xml node in

  • 0

Hi how do i retrieve the top level parent of an xml node in actionscript please?

    <companies>
        <company id="1" name="boo" level="1">
            <company id="2" name="hoo" level="2">
                <company id="3" name="ooo" level="3"/>
            </company>
        </company>
    </companies>

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-27T20:06:43+00:00Added an answer on May 27, 2026 at 8:06 pm

    Edit (final):

    I think I get what you are asking: what is the company.(@level = 1) node that has the selected company.(@level = 3) as a child. This is also known as an “ancestor” of the selected node. AS3 XML does not have a robust ancestor syntax, so you have to step upwards manually.

    For unknown levels of parenting, use a loop like the comments in this post discuss. Note that the following code uses the id attribute for searching. This is because all ids must be unique within a single XML, so you are guaranteed to find the id.

    var xml:XML = <companies>
            <company id="1" name="boo" level="1">
                <company id="2" name="hoo" level="2">
                    <company id="3" name="ooo" level="3"/>
                </company>
            </company>
            <company id="4" name="boo" level="1">
                <company id="5" name="hoo" level="2">
                    <company id="6" name="ooo" level="3"/>
                </company>
            </company>
            <company id="7" name="boo" level="1">
                <company id="8" name="hoo" level="2">
                    <company id="9" name="ooo" level="3"/>
                </company>
            </company>
        </companies>
    
    // just for testing:
    var selectedNodeXML:XML = 
        <company id="8" name="hoo" level="2" />
    
    var selectedID:String = selectedNodeXML.@id;
    trace("selectedID = " + selectedID);
    
    var ancestorID:String = "";
    
    for each( var companyNode:XML in xml.elements("*") )
    {
        trace( "searching: " + companyNode.toXMLString() );  
        trace( "res: " + (companyNode..company.(@id == selectedID).@id == selectedID));
        if(
           companyNode.@id == selectedNodeXML.@id
           //|| companyNode.contains(selectedNodeXML) // You can use this if nothing gets messed up . . .
           || companyNode..company.(@id == selectedID).@id == selectedID // . . . but I think this is more reliable.
        ){
            ancestorID = companyNode.@id.toString();
            break;
        }
    }
    
    trace( "significant ancestor ID: " + ancestorID );  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to understand how to retrieve the quotation from a top level
Is it possible to retrieve the geometric position (i.e. top/left offsets from either the
I retrieve XML data in Flex via HttpService. I have the resultFormat property on
Am new to LINQ, and am trying to retrieve the top 50 rows of
I have 100000 documents and I need to retrieve the top 10 documents that
I'm using a SQL-statement to retrieve the top 5 entries in a list: SELECT
I have some XML that is a single level with an attribute that I
I want to retrieve the path to a single node in a hierachical database
http://codex.wordpress.org/WPMU_Functions/get_current_site#Examples In Wordpress, I am trying to retrieve the site name inside a plugin
I have the below query, which basically it retrieves the 5 top most books

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.