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

发布于 2024-08-20 22:47:29 字数 159 浏览 3 评论 0原文

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

i want to pass xml format data into python from flex.i know how to pass from flex but my question is how can i get the passed data in python and then the data should be inserted into mysql.and aslo i want to retrieve the mysql data to the python(cgi),the python should convert all the data into xml format,and pass all the data to the flex..
Thank's in advance.....

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

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

发布评论

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

评论(1

情话已封尘 2024-08-27 22:47:29

请参阅 http://www.artima.com/weblogs/viewpost.jsp?thread =208528有关更多详细信息,这里是我认为您正在寻找的内容的简要概述。

SimpleXMLRPCServer 库允许您轻松创建服务器。以下是您可以创建的最简单的服务器,它提供了两种操作字符串的服务:

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()

一旦您与服务器建立连接,该服务器就像本地对象一样。您可以像调用该对象的普通方法一样调用服务器的方法。

这就是您所希望的最干净的 RPC 实现(并且存在其他 Python RPC 库;例如,CORBA 客户端)。但这都是基于文本的;当尝试创建具有漂亮 GUI 的精美应用程序时,并不是很令人满意。我们想要的是世界上最好的——Python(或你最喜欢的语言)在幕后完成繁重的工作,而 Flex 创造用户体验。

要使用该库,请下载它并将其解压到某个位置。该软件包包含所有源代码和编译后的 as3-rpclib.swc 库 - .swc 扩展名表示存档文件,并且可以提取该库的各个部分并将其合并到最终的 .swf 中。要将库包含在您的项目中,您必须通过转至“项目|属性”并选择“来告诉 Flexbuilder(您可以获得免费试用版或仅使用免费的命令行工具,并添加 Apollo 部分)该库所在的位置” Apollo 构建路径”,然后选择“库路径”选项卡并按“添加 SWC...”按钮。接下来,将命名空间 ak33m 添加到项目中,如下面的代码所示,然后就可以创建 XMLRPCObject。

注意:我在这里使用 Apollo 的唯一原因是我正在考虑具有漂亮 UI 的桌面应用程序。您可以轻松地将其设为 Flex 应用程序。

这是整个 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>

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.

The SimpleXMLRPCServer library allows you to easily create a server. 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). But it's all text based; not very satisfying when trying to create polished applications with nice GUIs. 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.

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. 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. Next, you add the namespace ak33m to your project as seen in the code below, and you're ready to create an XMLRPCObject.

Note: the only reason I used Apollo here was that I was thinking in terms of desktop applications with nice UIs. You can just as easily make it a Flex app.

Here's the entire Apollo application as a single MXML file, which I'll explain in detail:

<?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>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文