2011-01-11 12 views
0

からテキストノードの一意のパスを取得するのは、私はこのXML私はそれが必要だと思う。このフレックス:XML

/recipes/pubdate 
/recipes/totalNumbeOfResults 
/recipes/recipe/title 
/recipes/recipe/href 
/recipes/recipe/ingredients 

のような、私はそれのうち構造を持っている必要があります

<recipes> 
    <pudate>2011-11-01</pubdate> 
    <totalNumberOfResults>6</totalNumberOfResults> 
    <recipe> 
    <title>Ham And Cheese Omlet Roll Recipe</title> 
    <href>http://www.grouprecipes.com/38722/ham-and-cheese-omlet-roll.html</href> 
    <ingredients>cheddar cheese, dijon mustard, eggs, flour, milk, cream cheese, salt, green onion</ingredients> 
    </recipe> 
    <recipe> 
    <title>Egg Noodle Omlet Recipe</title> 
    <href>http://www.grouprecipes.com/63652/egg-noodle-omlet.html</href> 
    <ingredients>bacon, cheese, eggs, noodles, onions</ingredients> 
    </recipe> 
    <recipe> 
    <title>Sea Food Omlet Recipe</title> 
    <href>http://www.grouprecipes.com/8941/sea-food-omlet.html</href> 
    <ingredients>butter, crab meat, green onion, cheese, salt, capers</ingredients> 
    </recipe> 
    <recipe> 
    <title>French Fry - Tater Tot Omlet Recipe</title> 
    <href>http://www.grouprecipes.com/20924/french-fry---tater-tot-omlet.html</href> 
    <ingredients>eggs, french fries, salt, butter</ingredients> 
    </recipe> 
</recipes> 

をしたとしましょう再帰関数を使用して行うことができます。親切に助けてください。

答えて

0

これを試してみてください:

private function parseXML (xml : XML) : String 
{ 

    var path : String = ""; 

    if (xml.nodeKind() == "text") 
    { 
     var parent : XML = xml.parent(); 
     while (parent != null) 
     { 
      path = "/" + parent.name() + path; 
      parent = parent.parent(); 
     } 
     path += "\n"; 
     return path; 
    } 

    for each (var child:XML in xml.children()) 
    { 
     path += parseXML(child); 
    } 

    return path; 
} 

が続い trace(parseXML (myXML));

編集を呼び出す:私は私の最初の答えに少し速かった、これは正常に動作するはずです。

関連する問題