如何用Spyne描述元素属性 [英] How to describe element attributes with Spyne

查看:209
本文介绍了如何用Spyne描述元素属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我可以接受 Spyne的hello世界示例,但是当它出现时对于更复杂的事情,我面临着缺乏文档和高级示例的情况.就我而言,我有一个接受这样的主体的服务方法

I'm ok with Spyne's hello world examples, but when it comes to something more complex I faced with lack of documentation and advanced examples. In my case I have a service method which accepts body like this

<OTA_HotelAvailRQ xmlns="http://www.opentravel.org/OTA/2003/05" Version="1.0" TimeStamp="2005-08-01T09:30:47+02:00" EchoToken="fb57388d" AvailRatesOnly="true">
  <AvailRequestSegments>
    <AvailRequestSegment AvailReqType="Room">
      <HotelSearchCriteria>
        <Criterion>
          <HotelRef HotelCode="HOTEL1"/>
        </Criterion>
      </HotelSearchCriteria>
    </AvailRequestSegment>
  </AvailRequestSegments>
</OTA_HotelAvailRQ>

您能帮我实现接受此类请求的服务吗?

Can you help me to implement a service that accepts this kind of request?

推荐答案

离我远去:

class HotelReference(ComplexModel):
    __namespace__ = 'http://www.opentravel.org/OTA/2003/05'

    HotelCode = XmlAttribute(Unicode)

class Criterion(ComplexModel):
    __namespace__ = 'http://www.opentravel.org/OTA/2003/05'

    HotelRef = HotelReference

class AvailRequestSegment(ComplexModel):
    __namespace__ = 'http://www.opentravel.org/OTA/2003/05'

    AvailReqType = XmlAttribute(Unicode(values=["Room", "House", "Condo", "Castle"]))
    HotelSearchCriteria = Criterion.customize(max_occurs='unbounded')

class HotelAvailRQ(ComplexModel):
    __namespace__ = 'http://www.opentravel.org/OTA/2003/05'

    Version = XmlAttribute(Unicode)
    TimeStamp = XmlAttribute(DateTime)
    EchoToken = XmlAttribute(ByteArray)
    AvailRatesOnly XmlAttribute(Boolean)

    AvailRequestSegments = Array(AvailRequestSegment)

这篇关于如何用Spyne描述元素属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆