如何将 XML 转换为 ActionScript 对象

发布于 2024-12-10 11:45:38 字数 612 浏览 0 评论 0原文

我有一个 xml 文件和同一 xml 文件的动作脚本类。

例如: xml 文件

 <element name="Student">
    <element name="FirstName">
        <value>Sachin</value>
    </element>
</element>

as3 类:

Student.as

package generated {     
     public class Student{    

       public var firstName:FirstName = new FirstName();    
    }    
}

FirstName.as
package generated { 
     public class FirstName{
        public var value:String;
    }
}

现在,我想将上面的 xml 转换为 Actionscript 对象。

有什么工具吗?

请帮忙......谢谢......:)

I have a xml file and actionscript classes for same xml file.

eg: xml file

 <element name="Student">
    <element name="FirstName">
        <value>Sachin</value>
    </element>
</element>

as3 classes:

Student.as

package generated {     
     public class Student{    

       public var firstName:FirstName = new FirstName();    
    }    
}

FirstName.as
package generated { 
     public class FirstName{
        public var value:String;
    }
}

Now, I want to convert above xml into actionscript object.

Is there any tool?

Please, help...... Thanks...:)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

似狗非友 2024-12-17 11:45:38

我相信您的选择是:

  • 自己解析和反序列化,将 XML 映射到您自己的对象。
  • 使用库中的序列化器/反序列化器。
  • 转换为对象,使用 HTTPService。

使用服务方法,Flex 可以将 XML 作为本机对象进行处理;但是,这不会映射到您键入的类。您也许能够遵循 Flex 远程处理服务的模式来正确映射到类定义,而无需管道键入。

不完全是你想要的,但是这里已经要求将 XML 转换为对象: 将 XML 字符串转换为 Actionscript 中的对象

I believe your choices are:

  • Parse and deserialize yourself, mapping your XML to your own objects.
  • Use a serializer / deserializer from a library.
  • Cast as objects, use a HTTPService.

Using service methods, Flex can handle XML as native objects; however, this would not map to classes you've typed. You might be able to follow patterns of Flex remoting services to correctly map to class definitions without duct typing.

Not quite what you're after, but turning XML to an object has been asked here: Turn an XML string into an Object in Actionscript

活泼老夫 2024-12-17 11:45:38
public var xmlFileName:String;
    private var urlL:URLLoader = new URLLoader();
    private var urlR:URLRequest;
    public var xml:XML = new XML();
    public var target_id:String= new String();

    public function loadXML(xmlS:String):void
    {
        xmlFileName = xmlS;
        urlR =  new URLRequest(xmlFileName);            
      //  urlL.addEventListener(ProgressEvent.PROGRESS, onProgressAction);
        urlL.addEventListener(Event.COMPLETE, onLoadedAction);
       // urlL.addEventListener(IOErrorEvent.IO_ERROR, errorAction);
        urlL.load(urlR);            
    }
    public function onLoadedAction(e:Event):void
    {
        xml = XML(e.target.data);
        target_id = xml.element.value[0];
        dispatchEvent ( new Event ( Event.COMPLETE ) )
        //trace(xml);
    }  

// 在你的 FirstName 类中

private function init():void
{
    xmlData = new loadXML("list.xml");
    // listen for loading completed
    xmlData.addEventListener ( Event.COMPLETE, handleXMLLoaded );
}

private function handleXMLLoaded (e:Event):void
{
   var xmlF:XML = xmlData.xml
   var value:String = xmlData.target_id;
   //trace(xmlF); 
}
public var xmlFileName:String;
    private var urlL:URLLoader = new URLLoader();
    private var urlR:URLRequest;
    public var xml:XML = new XML();
    public var target_id:String= new String();

    public function loadXML(xmlS:String):void
    {
        xmlFileName = xmlS;
        urlR =  new URLRequest(xmlFileName);            
      //  urlL.addEventListener(ProgressEvent.PROGRESS, onProgressAction);
        urlL.addEventListener(Event.COMPLETE, onLoadedAction);
       // urlL.addEventListener(IOErrorEvent.IO_ERROR, errorAction);
        urlL.load(urlR);            
    }
    public function onLoadedAction(e:Event):void
    {
        xml = XML(e.target.data);
        target_id = xml.element.value[0];
        dispatchEvent ( new Event ( Event.COMPLETE ) )
        //trace(xml);
    }  

//and in your FirstName class

private function init():void
{
    xmlData = new loadXML("list.xml");
    // listen for loading completed
    xmlData.addEventListener ( Event.COMPLETE, handleXMLLoaded );
}

private function handleXMLLoaded (e:Event):void
{
   var xmlF:XML = xmlData.xml
   var value:String = xmlData.target_id;
   //trace(xmlF); 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文