Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

How to find parent node using child node or attribute?

New Here ,
Sep 06, 2015 Sep 06, 2015

Hi People,

How to find the parent node of child node in xml using as3?

My XML structure

<video id="" name="test">

  <subVideo id="" name="test1" src="video.mp4" content="video" />

  <subVideo id="" name="test2" src="video.mp4" content="video" />

</video>

I want to get parent node name of subVideo node.

Please help me.

Thank you people.

TOPICS
ActionScript
1.6K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Sep 07, 2015 Sep 07, 2015

the parent's node name is video.

do you mean you want to get the node itself or it's id or name given a particular subvideo id or name or src?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guest
Sep 08, 2015 Sep 08, 2015
LATEST

Assuming you have already created your XML object in Flash and have a reference to one of the children (<subVideo> tag in the example you provided) as either an XML object or XMLList object, you can call the .parent() method to get a reference to the parent of the <subVideo> tag and then call the .attribute() method passing "name" into the method call and it will return a String of "test". Below is the code example I created real quick. It assumes that you have an XML file named "test.xml" in the same directory as the FLA/SWF. The "test.xml" file I created for testing contains the exact example you provided.

import flash.net.URLLoader;

import flash.net.URLRequest;

import flash.events.Event;

var xml:XML;

var urlLoader:URLLoader = new URLLoader();

urlLoader.addEventListener(Event.COMPLETE, onFileLoad);

urlLoader.load(new URLRequest("test.xml"));

function onFileLoad(e:Event):void {

  xml = new XML(e.target.data);

  // xml.children() = XMLList object of the two <subVideo> tags

  // xml.children().parent() is, in this case, an XML object identical to the "xml" variable

  // xml.childnre().parent().attribute("name") returns the String value of the "name" attribute

  trace(xml.children().parent().attribute("name"));// returns String value of "test"

}

http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/XML.html

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines