使用XML文件的结构

时间:2011-11-15 01:04:08

标签: xml actionscript-3 flex

我正在尝试使用Ravis lib进行数据可视化,而Ravis使用的XML文件结构与我们公司使用的不同。具体如下:

Ravis XML结构:

<Family>
<Node id="1" name="Father" desc="Head of the family" class="HOF"/>
<Node id="2" name="Mother" desc="Wife of Father" class="firstLady"/>
<Node id="3" name="Son" desc="Son" class="member"/>
<Node id="4" name="Daughter" desc="Daughter" class="member"/> 
<Node id="5" name="Daughter In Law" desc="Wife of Son" class="extendedMember"/>
<Node id="6" name="Grandson" desc="Child of Son" class="childMember"/>
<Edge fromID="1" toID="2" name="married" edgeClass="marriage"/>
<Edge fromID="1" toID="3" name="gave birth to" edgeClass="birth"/>
<Edge fromID="2" toID="3" name="gave birth to" edgeClass="birth"/>
<Edge fromID="1" toID="4" name="gave birth to" edgeClass="birth"/>
<Edge fromID="2" toID="4" name="gave birth to" edgeClass="birth"/>  
<Edge fromID="3" toID="5" name="married" edgeClass="marriage"/>
<Edge fromID="3" toID="6" name="gave birth to" edgeClass="birth"/>
<Edge fromID="5" toID="6" name="gave birth to" edgeClass="birth"/>
</Family>

但我们遵循的结构是

<Family>
<Node>
    <individual id="1" name="Father" desc="Head of the family" class="HOF"/>
</Node>
<Node>
    <individual id="2" name="Mother" desc="Wife of Father" class="firstLady"/>
</Node>
<Node>
    <individual id="3" name="Son" desc="Son" class="member"/>
</Node>
<Node>
    <individual id="4" name="Daughter" desc="Daughter" class="member"/>
</Node>
<Node>
    <individual id="5" name="Daughter In Law" desc="Wife of Son" class="extendedMember"/>
</Node>
<Node>
    <individual id="6" name="Grandson" desc="Child of Son" class="childMember"/>
</Node>
<Edge>
    <relation fromID="1" toID="2" name="married" edgeClass="marriage"/>
</Edge>
<Edge>
    <relation fromID="1" toID="3" name="gave birth to" edgeClass="birth"/>
</Edge>
<Edge>
    <relation fromID="2" toID="3" name="gave birth to" edgeClass="birth"/>
</Edge>
<Edge>
    <relation fromID="1" toID="4" name="gave birth to" edgeClass="birth"/>
</Edge>
<Edge>
    <relation fromID="2" toID="4" name="gave birth to" edgeClass="birth"/>
</Edge>
<Edge>
    <relation fromID="3" toID="5" name="married" edgeClass="marriage"/>
</Edge>
<Edge>
    <relation fromID="3" toID="6" name="gave birth to" edgeClass="birth"/>
</Edge>
<Edge>
    <relation fromID="5" toID="6" name="gave birth to" edgeClass="birth"/>
</Edge>
 </Family>

现在我无法弄清楚如何在图表上显示XML文件中的数据。我正在尝试使用AS3和FLex 4来完成此操作。代码已经存在于Ravis社区,但它不会以我希望它重做的格式读取XML文件。

非常感谢任何帮助。

2 个答案:

答案 0 :(得分:2)

您可以使用e4x语法动态解析XML,不是吗?

        var to:XML = <Family/>;

        for each (var ind:XML in from..individual) {

            var indTo:XML = ind.copy();
            indTo.setName("Node");

            to.appendChild(indTo);
        }

        for each (var rel:XML in from..relation) {

            var relTo:XML = rel.copy();
            relTo.setName("Edge");

            to.appendChild(relTo);
        }

答案 1 :(得分:0)

XSLT可能是“快速”方式,因为您无法改变公司结构。但是不知道你从哪里开始把它放进去了。