a question about parsing xml file in Flex

后端 未结 2 1041
终归单人心
终归单人心 2021-01-25 19:14

I am faced with a small project now,in which I have to present a peoridic table to the user.However,it is bit more complicated than just a pure peoridic table image file.Let me

相关标签:
2条回答
  • 2021-01-25 19:30

    XML parsing is pretty easy in actionscript 3 with E4X and somewhat similar to C#.

    e.g.

    var table:XML = <constraints>
    <element>
     <name>Calcium</name>
     <abbreviation>Ca</abbreviation>
     <emissions>
      <wavelength>118</wavelength>
     </emissions>
     <standards>
      <concentration>0.01</concentration>
      <concentration>0.1</concentration>
     </standards>
    </element>
    </constraints>
    trace(table.element.name);
    

    Do checkout the E4X tutorial on the Yahoo Developer Network to get started easily. The rest should be easy enough.

    For point 2 you should just loop through the element names and then enable their view/visual asset equivalent.

    e.g.

    for each (var element:XML in table.element.*) trace(element.name);//enable here instead of tracing
    

    Update

    I had a bit of fun with the great libspark SvgParser and the wikipedia periodic table svg. This is NOT how anyone should write code, this is just a quick and dirty test.

    You can view the test here and the source here.

    here's a preview: flex 3 periodic table test

    Also displaying the C# version of parsing would help. And I found another great E4X article.

    HTH, George

    0 讨论(0)
  • 2021-01-25 19:54

    You also need to think about how you are going to get your XML into your flex application because flex can not read from the local file server. You can bundle the XML with your application or load it from the server.

    0 讨论(0)
提交回复
热议问题