flex xml Children() 方法奇怪的行为
我有以下 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 填充了高级数据网格,但问题是未检测到要求:
我已经重写了 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 的源代码,因为它不是开源的。有人能告诉我发生了什么事吗?这是一个错误还是其他什么?
I have the following xml declaration:
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>;
I populated an advanced datagrid with this xml but the problem is that a requirement isn't detected: <Requirement ID="REQ-BUS-3.2.1" title="exigence bus3" description="blabla 321" testable="true"/>
I've overriden a method of the HierarchicalData class to see what happenned:
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());
}
}
And here is the result (console), that I just don't understand at all:
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():
The node isn't detected by the children() method but it exists. The problem is that I can't look at the source code of XML.abc cause it isn't open-source. Can someone tell me what is happenning? Is it a bug or something else?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该节点由
children()
方法按照您的预期方式选取,因为否则children()
的length()
将是0.你要明白的是,trace(node.children());
实际上意味着trace(XMLList(node.children()).toString());
- 您正在 XMLList 上调用 toString() - 其输出可能有许多不同的结果,但显然不是非常可预测的结果:为了确保获得子节点的完整 xml,请尝试:
The node is picked up by the
children()
method just the way you intended, because otherwise thelength()
ofchildren()
would be 0. What you have to understand is thattrace( node.children());
actually meanstrace ( XMLList( node.children() ).toString());
- you are calling toString() on an XMLList - the output of which can have a number of different results, though obviously not very predictable ones:To make sure you get the full xml of your child node, try: