2012-02-20 6 views
0

私は、以下のXML宣言があります。フレックスXML子供()メソッドの奇妙な行動

public var reqData:XML = <root> 
    <Requirement ID="REQ-GEN-0.1" title="exigence gen 1" description="blabla 01" testable="true"/> 
    <RequirementSet ID="GUI REQ"> 
    <Requirement ID="REQ-GUI-1.1" title="exigence ihm 1" description="blabla 11" testable="true"/> 
    <Requirement ID="REQ-GUI-1.2" title="exigence ihm 2" description="blabla 12" testable="false"/> 
    </RequirementSet> 
    <RequirementSet ID="PERF REQ"> 
    <Requirement ID="REQ-PERF-2.1" title="exigence perf 1" description="blabla 21" testable="true"/> 
    <Requirement ID="REQ-PERF-2.2" title="exigence perf 2" description="blabla 22" testable="false"/> 
    <Requirement ID="REQ-PERF-2.3" title="exigence perf 3" description="blabla 23" testable="true"/> 
    <Requirement ID="REQ-PERF-2.4" title="exigence perf 4" description="blabla 24" testable="false"/> 
    <Requirement ID="REQ-PERF-2.5" title="exigence perf 5" description="blabla 25" testable="false"/> 
    <Requirement ID="REQ-PERF-2.6" title="exigence perf 6" description="blabla 26" testable="false"/> 
    </RequirementSet> 
    <RequirementSet ID="BUS REQ"> 
    <RequirementSet ID="BUS 1 REQ"> 
     <Requirement ID="REQ-BUS-3.1.1" title="exigence bus 1" description="blabla 311" testable="false"/> 
     <Requirement ID="REQ-BUS-3.1.2" title="exigence bus 2" description="blabla 312" testable="true"/> 
    </RequirementSet> 
    <RequirementSet ID="BUS 2 REQ"> 
     <Requirement ID="REQ-BUS-3.2.1" title="exigence bus3" description="blabla 321" testable="true"/> 
    </RequirementSet> 
    <RequirementSet ID="BUS 3 REQ"/> 
    </RequirementSet> 
</root>; 

を私は、このXMLとの高度なデータグリッドを埋めたが、問題は、要求が検出されないということです。<Requirement ID="REQ-BUS-3.2.1" title="exigence bus3" description="blabla 321" testable="true"/>

私はhappennedものを見るためにHierarchicalDataクラスのメソッドをオーバーライドしました:

override public function canHaveChildren(node:Object):Boolean 
     { 
      if (node is XML && node != null){ 
       var xmlNode:XML = node as XML; 
       trace("node:"+node); 
       trace("node.children:"+node.children()); 
       trace("xmlNode.name:"+xmlNode.name()); 
       trace("xmlNode.localName:"+xmlNode.localName()); 
       trace("xmlNode.attributes:"+xmlNode.attributes()); 
       trace("xmlNode.attributes:"+xmlNode.nodeKind()); 
       trace("xmlNode.children():"+xmlNode.children()); 
       trace("xmlNode.children().length():"+xmlNode.children().length()); 

       if(xmlNode.children().length()>0){ 
        var xmlNodeChildren:XMLList = xmlNode.children() as XMLList; 
        var xmlNodeFirstChild:XML = xmlNodeChildren[0]; 
        trace("xmlNodeFirstChild:"+xmlNodeFirstChild); 
        trace("xmlNodeFirstChild.name():"+xmlNodeFirstChild.name()); 
        trace("xmlNodeFirstChild.comments():"+xmlNodeFirstChild.comments()); 
        trace("xmlNodeFirstChild.attributes():"+xmlNodeFirstChild.attributes()); 
        trace("xmlNodeFirstChild.nodeKind():"+xmlNodeFirstChild.nodeKind()); 
        trace("xmlNodeFirstChild.descendants():"+xmlNodeFirstChild.descendants()); 
       } 


      } 

そしてここでは、結果は私は全く理解していないこと、(コンソール)である:

node:<RequirementSet ID="BUS 2 REQ"> 
    <Requirement ID="REQ-BUS-3.2.1" title="exigence bus3" description="blabla 321" testable="true"/> 
</RequirementSet> 
node.children: 
xmlNode.name:RequirementSet 
xmlNode.localName:RequirementSet 
xmlNode.attributes:BUS 2 REQ 
xmlNode.attributes:element 
xmlNode.children(): 
xmlNode.children().length():1 
xmlNodeFirstChild: 
xmlNodeFirstChild.name():Requirement 
xmlNodeFirstChild.comments(): 
xmlNodeFirstChild.attributes():REQ-BUS-3.2.1exigence bus3blabla 321true 
xmlNodeFirstChild.nodeKind():element 
xmlNodeFirstChild.descendants(): 

ノードはchildren()メソッドでは検出されませんが存在します。問題は、オープンソースではないため、XML.abcのソースコードを見ることができないということです。誰かが起こっていることを教えてもらえますか?それはバグなのでしょうか? XMLListオブジェクトに呼び出しているのtoString() - そうchildren()length()は次のようになりますので

答えて

1

ノードは、children()方法あなたが意図しただけの方法によってピックアップされる0あなたが理解しなければならないことはtrace(node.children());が実際にtrace (XMLList(node.children()).toString());を意味していることです - の出力は明らかに非常に予測できないものが、異なる結果の数を持つことができます。

var xml : XML = <node><child>MyText</child></node>; 
trace (xml.children()); 
// => MyText 

xml = <node><child value="MyText" /></node>; 
trace (xml.children()); 
// => nothing 

xml = <node><child key="myKey" id="1" value="MyText" /></node>; 
trace (xml.children()); 
// => nothing 

xml = <node><child id="1" key="text">MyText</child></node>; 
trace (xml.children()); 
// => MyText 

xml = <node><child id="1">MyText<child id="2">MyOtherText</child></child></node>; 
trace (xml.children()); 
// => <child id="1">MyText<child id="2">MyOtherText</child></child> 

があなたの子ノードの完全なXMLを取得することを確認するには、試してみてください。

var childXML : String = node.children().length() > 0 ? node.children()[0].toXMLString():"empty"); 
trace("node.child#0:"+ childXML); 
// output: 
// node.child#0:<Requirement ID="REQ-BUS-3.2.1" title="exigence bus3" description="blabla 321" testable="true"/> 
+0

ええ、ありがとう、私の悪い^^。 – TheFrenchGuy