简体   繁体   English

我如何将XML格式的数据从flex传递到python

[英]how can i pass xml format data from flex to python

我想将XML格式的数据从flex.python传递给python,我知道如何从flex传递信息,但我的问题是我如何才能在python中获取传递的数据,然后将数据插入mysql.and我也想检索mysql数据到python(cgi),python应该将所有数据转换为xml格式,并将所有数据传递给flex ..谢谢。

See http://www.artima.com/weblogs/viewpost.jsp?thread=208528 for more details, here is a breif overview of what I think you are looking for. 有关更多详细信息,请参见http://www.artima.com/weblogs/viewpost.jsp?thread=208528 ,这是我想寻找的东西的简要概述。

The SimpleXMLRPCServer library allows you to easily create a server. SimpleXMLRPCServer库使您可以轻松创建服务器。 Here's about the simplest server you can create, which provides two services to manipulate strings: 这是您可以创建的最简单的服务器,它提供了两种服务来处理字符串:

import sys
from random import shuffle
from SimpleXMLRPCServer import SimpleXMLRPCServer

class MyFuncs:
    def reverse(self, str) :
        x = list(str);
        x.reverse();
        return ''.join(x);
    def scramble(self, str):
        x = list(str);
        shuffle(x);
        return ''.join(x);

server = SimpleXMLRPCServer(("localhost", 8000))
server.register_instance(MyFuncs())
server.serve_forever()

Once you make a connection to the server, that server acts like a local object. 与服务器建立连接后,该服务器将充当本地对象。 You call the server's methods just like they're ordinary methods of that object. 您调用服务器的方法就像它们是该对象的普通方法一样。

This is about as clean an RPC implementation as you can hope for (and other Python RPC libraries exist; for example, CORBA clients). 正如您所希望的那样,这几乎是一个干净的RPC实现(以及其他Python RPC库;例如CORBA客户端)。 But it's all text based; 但这全是基于文本的; not very satisfying when trying to create polished applications with nice GUIs. 尝试使用精美的GUI创建精美的应用程序时,效果不是很好。 What we'd like is the best of all worlds -- Python (or your favorite language) doing the heavy lifting under the covers, and Flex creating the user experience. 我们想要的是世界上最好的-Python(或您喜欢的语言)在后台进行繁重的工作,而Flex创造了用户体验。

To use the library, download it and unpack it somewhere. 要使用该库,请下载该库并将其解压缩到某处。 The package includes all the source code and the compiled as3-rpclib.swc library -- the .swc extension indicates an archive file, and pieces of this library can be pulled out and incorporated into your final .swf. 该软件包包括所有源代码和已编译的as3-rpclib.swc库-.swc扩展名表示一个存档文件,可以将该库的各个部分提取出来并合并到最终的.swf中。 To include the library in your project, you must tell Flexbuilder (you can get a free trial or just use the free command-line tools, and add on the Apollo portion) where the library is located by going to Project|Properties and selecting "Apollo Build Path," then choosing the "Library path" tab and pressing the "Add SWC..." button. 要将库包含在您的项目中,您必须通过转到Project | Properties并选择“”,告知Flexbuilder(您可以免费试用或仅使用免费的命令行工具,并添加Apollo部分)库的位置。 Apollo构建路径”,然后选择“库路径”标签,然后按“添加SWC ...”按钮。 Next, you add the namespace ak33m to your project as seen in the code below, and you're ready to create an XMLRPCObject. 接下来,将名称空间ak33m添加到项目中,如下面的代码所示,并准备创建XMLRPCObject。

Note: the only reason I used Apollo here was that I was thinking in terms of desktop applications with nice UIs. 注意:我在这里使用Apollo的唯一原因是我在考虑具有精美UI的桌面应用程序。 You can just as easily make it a Flex app. 您可以轻松地使其成为Flex应用程序。

Here's the entire Apollo application as a single MXML file, which I'll explain in detail: 这是整个Apollo应用程序的单个MXML文件,我将对其进行详细说明:

<?xml version="1.0" encoding="utf-8"?>
<mx:ApolloApplication xmlns:mx="http://www.adobe.com/2006/mxml" 
    xmlns:ak33m="http://ak33m.com/mxml" layout="absolute">
    <mx:Form>
        <mx:FormHeading label="String Modifier"/>
        <mx:FormItem label="Input String">
            <mx:TextInput id="instring" change="manipulate()"/>
        </mx:FormItem>
        <mx:FormItem label="Reversed">
            <mx:Text id="reversed"/>
        </mx:FormItem>
        <mx:FormItem label="Scrambled">
            <mx:Text id="scrambled"/>
        </mx:FormItem>
    </mx:Form>
    <ak33m:XMLRPCObject id="server" endpoint="http://localhost:8000"/>
    <mx:Script>
        <![CDATA[
            import mx.rpc.events.ResultEvent;
            import mx.rpc.events.FaultEvent;
            import mx.rpc.AsyncToken;
            import mx.controls.Alert;
            import mx.collections.ItemResponder;
            private function manipulate() : void {
                server.reverse(instring.text).addResponder(new ItemResponder(reverseResult, onFault));
                server.scramble(instring.text).addResponder(new ItemResponder(scrambleResult, onFault));
            }
            private function reverseResult(event : ResultEvent, token : AsyncToken = null) : void {
                reversed.text = event.result.toString();
            }
            private function scrambleResult(event : ResultEvent, token : AsyncToken = null) : void {
                scrambled.text = event.result.toString();
            }
            private function onFault (event : FaultEvent, token : AsyncToken = null) : void {
                Alert.show(event.fault.faultString, event.fault.faultCode);
            }           
        ]]>
    </mx:Script>
</mx:ApolloApplication>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM