使用Action脚本3获取所需的标记表单XML和必需的子标记?

时间:2011-09-13 04:33:01

标签: xml actionscript-3 flex4

我有一个XML架构。我想使用动作脚本3代码只读取表格标签及其几何标签。任何想法。

<table name="TableBase 1" id="TableBase3010" overflow="false" direction="lr-tb" suppress-empty-lines="false">
      <style-ref name="default"/>
      <geometry size="absolute" position="absolute">
        <location left="117" top="102"/>
        <size width="341" height="80"/>
        <transform rotation="0"/>
      </geometry>
      <columns number-of-columns="1" gutter="0" align-bottoms="false"/>
      <header>
        <row>
          <cell>
            <objects>
              <text name="SingleLineText3081" id="ElxSingleLineText3081">
                <style-ref name="default"/>
                <geometry size="absolute" position="absolute">
                  <location left="0" top="0"/>
                  <size width="341" height="20"/>
                  <transform rotation="0"/>
                </geometry>
                <content value="Text"/>
              </text>
            </objects>
          </cell>
        </row>
      </header>

      <body>
        <row>
          <cell>
            <objects>
              <text name="SingleLineText3150" id="ElxSingleLineText3150">
                <style-ref name="default"/>
                <geometry size="absolute" position="absolute">
                  <location left="0" top="0"/>
                  <size width="341" height="20"/>
                  <transform rotation="0"/>
                </geometry>
                <content value="Text"/>
              </text>
            </objects>
          </cell>
        </row>
      </body>
      <footer>
        <row>
          <cell>
            <objects>
              <text name="SingleLineText3279" id="ElxSingleLineText3279">
                <style-ref name="default"/>
                <geometry size="absolute" position="absolute">
                  <location left="0" top="0"/>
                  <size width="341" height="20"/>
                  <transform rotation="0"/>
                </geometry>
                <content value="Text"/>
              </text>
            </objects>
          </cell>
        </row>
      </footer>
    </table>

感谢提前!!!!!!!

2 个答案:

答案 0 :(得分:0)

<?xml version="1.0" encoding="utf-8"?>

<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark" 
               xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Declarations>
        <fx:XML id="treeDP">
            <table name="TableBase 1" id="TableBase3010" overflow="false" direction="lr-tb" suppress-empty-lines="false">
                <style-ref name="default"/>
                <geometry size="absolute" position="absolute">
                    <location left="117" top="102"/>
                    <size width="341" height="80"/>
                    <transform rotation="0"/>
                </geometry>
                <columns number-of-columns="1" gutter="0" align-bottoms="false"/>
                <header>
                    <row>
                        <cell>
                            <objects>
                                <text name="SingleLineText3081" id="ElxSingleLineText3081">
                                    <style-ref name="default"/>
                                    <geometry size="absolute" position="absolute">
                                        <location left="0" top="0"/>
                                        <size width="341" height="20"/>
                                        <transform rotation="0"/>
                                    </geometry>
                                    <content value="Text"/>
                                </text>
                            </objects>
                        </cell>
                    </row>
                </header>

                <body>
                    <row>
                        <cell>
                            <objects>
                                <text name="SingleLineText3150" id="ElxSingleLineText3150">
                                    <style-ref name="default"/>
                                    <geometry size="absolute" position="absolute">
                                        <location left="0" top="0"/>
                                        <size width="341" height="20"/>
                                        <transform rotation="0"/>
                                    </geometry>
                                    <content value="Text"/>
                                </text>
                            </objects>
                        </cell>
                    </row>
                </body>
                <footer>
                    <row>
                        <cell>
                            <objects>
                                <text name="SingleLineText3279" id="ElxSingleLineText3279">
                                    <style-ref name="default"/>
                                    <geometry size="absolute" position="absolute">
                                        <location left="0" top="0"/>
                                        <size width="341" height="20"/>
                                        <transform rotation="0"/>
                                    </geometry>
                                    <content value="Text"/>
                                </text>
                            </objects>
                        </cell>
                    </row>
                </footer>
            </table>    
    </fx:XML>

</fx:Declarations>
<fx:Script>
    <![CDATA[
        protected function onClick(event:Event):void
        {
        for each(var item:XML in treeDP){
            textArea1.text=item;
            textArea2.text=item.child("geometry");
            }
        }
    ]]>
</fx:Script>

<s:Button id="Click" click="onClick(event)" x="1" y="57" label="Click"/>
<mx:TextArea id="textArea1" x="95" y="17" width="456" height="335"/>
<mx:TextArea id="textArea2" x="559" y="17" width="369" height="336"/>
</s:Application>

答案 1 :(得分:0)

让我们假设您的XML存储在名为'xml'

的变量中
var xml:XML;

现在xml将存储您的代码,您可以将几何详细信息作为XMLList

获取
var xmlList:XMLList = xml.child("geometry")
trace(xml.child("geometry")[0].toXMLString());//<location left="117" top="102"/>
trace(xml.child("geometry")[1].toXMLString());//<size width="341" height="80"/>