我有以下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"/>
我已经覆盖了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的源代码,因为它不是开源的。有人能告诉我发生了什么事吗?这是一个错误还是其他什么?
答案 0 :(得分:1)
children()
方法按照您的预期方式选择节点,否则length()
的{{1}}将为0.您必须了解{{1}实际上意味着children()
- 你在XMLList上调用toString() - 其输出可以有许多不同的结果,但显然不是很可预测的结果:
trace( node.children());
要确保获得子节点的完整xml,请尝试:
trace ( XMLList( node.children() ).toString());