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

Accessing XML nodes through attributes.

Explorer ,
Aug 13, 2018 Aug 13, 2018

Copy link to clipboard

Copied

This is my XML:

<root>

  <terms>

     <word type="term1" value="Definition for term1."/>

     <word type="term2" value="Definition for term2."/>   

     <word type="term3" value="Definition for term3."/>

     <word type="term4" value="Definition for term4."/>

  </terms>

</root>

To access particular node I use the following:

var definition:XMLList = myXml.terms.word.@type;

This allows me to easily access any node just by typing: definition

So, far I've built a list of words consisting of attributes, and if I click on of them, it displays the "value" attibute.

However, I'd like to add a search option, and this is where I have some problems. I know I can find an attribute with the following:

var definition:XMLList = myXml.terms.word.(@type == "term3");

But how do I retrieve appropriate "value" attribute corresponding to that "type" attribute? Is there any way to get the number of this node, so I could use then something like valueXMLList, or maybe there's a different, better way?

TOPICS
ActionScript

Views

396

Translate

Translate

Report

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 ,
Aug 13, 2018 Aug 13, 2018

Copy link to clipboard

Copied

LATEST

function completeF(e:Event):void{

var myXml=XML(e.target.data);

nodeF(myXml.terms.word.(@type=='term3'));

}

function nodeF(list:XMLList):void {

var item:XML;

for each(item in list) {

trace(item.@value);

}

}

Votes

Translate

Translate

Report

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