[使用generateDS通过xsd生成XML请求

问题描述 投票:1回答:1

我想a)生成XML请求b)和解析响应

基于我从一个OEM处获得的纲要(.xsd)。

我在网上研究了generateDS,似乎是我一直在寻找的一种,但是我正在努力使其发挥作用。

我能够生成Python类,但是我不确定这是否是正确的方法。

1)我正在尝试使用从XSD创建的python模块在运行时生成xml请求,这种方法是否适用于生产应用程序。要么我应该通过xml.etree.ElementTree生成xml请求吗(我确实知道在后台generateDS也正在使用它)。

2)当我实例化一个类时,它不会生成完整的xml输出。

最终结果应该是这样的:

<BroadsoftDocument protocol = "OCI" xmlns="C" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
    <sessionId xmlns="">10.21.197.17,22307196,1562598749074</sessionId>

    <command xsi:type="AuthenticationRequest" xmlns="">
        <userId>[email protected]</userId>
    </command>
</BroadsoftDocument>```


Help on class AuthenticationRequest in module OCISchemaLogin_gds:

class AuthenticationRequest(OCIRequest)
 |  AuthenticationRequest(echo=None, userId=None, **kwargs_)
 |  
 |  AuthenticationRequest is 1st stage of the 2 stage OCI login process.
 |  
 |  Method resolution order:
 |      AuthenticationRequest
 |      OCIRequest
 |      OCICommand
 |      GeneratedsSuper
 |      builtins.object
 |  
 |  Methods defined here:
 |  
 |  __init__(self, echo=None, userId=None, **kwargs_)
 |      Initialize self.  See help(type(self)) for accurate signature.
 |  


CODE:
auth_req = OCISchemaLogin_gds.AuthenticationRequest(userId = self.userId,)
command =[OCISchemaLogin_gds.OCICommand(extensiontype_='AuthenticationRequest') ]
message = OCISchemaLogin_gds.OCIMessage(protocol='OCI',sessionId=session, userId=self.userId, command= command)
message.export(sys.stdout,1)


OUTPUT:

    <OCIMessage  xmlns:None="C"  protocol="OCI">     <sessionId>992df876f417bc9215e68dffdac436b7b5fb485bc2dfb5cf8cf324c0ff143c0f</sessionId>
        <userId>chaadars_admin_lab</userId>
        <OCICommand xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="AuthenticationRequest"/>
    </OCIMessage>
SUCCESSFUL

我什至正确使用了吗?

xml python-3.x xsd
1个回答
0
投票

当您将genertaDS下载到计算机时,打开tutorial / code / my_test.py,将获得一个示例,该示例将从people.xsd(xml模式)构建people.xml。顺便说一句,它也基于具有所有类的架构创建people_api.py。

阶段:1.从cmd运行:

python generateDS.py -o people.py people.xsd

这将基于具有所有类的架构来创建people_api.py。2.从cmd运行:

python my_test.py

这会将xml输出输出到stdout。

© www.soinside.com 2019 - 2024. All rights reserved.