Python的XMLSchema绑定包 PyXB

码农软件 · 软件分类 · XML相关工具 · 2019-09-18 22:29:27

软件介绍

PyXB (“pixbee”) 是一个纯 Python 的类库用来根据 XML Schema 生成对应的 Python 类,开发人员可以使用这些类来操作XML Schema 数据。

示例代码:

import weather
import time
import pyxb.utils.domutils as domutils
import sys
import pyxb.standard.bindings.soapenv as soapenv
import pyxb.standard.bindings.soapenc as soapenc
import urllib2

zip = 85711
if 1 < len(sys.argv):
zip = int(sys.argv[1])

# Create an envelope, and give it a body that is the request for the
# service we want.
env = soapenv.Envelope()
env.setBody(weather.GetCityForecastByZIP(ZIP=zip))

# Invoke the service
uri = urllib2.Request('http://ws.cdyne.com/WeatherWS/Weather.asmx',
env.toxml(),
{ 'SOAPAction' : "http://ws.cdyne.com/WeatherWS/GetCityForecastByZIP", 'Content-Type': 'text/xml' } )
rxml = urllib2.urlopen(uri).read()

# Convert the response to a SOAP envelope, then extract the actual
# response from the wildcard elements of the body. Note that because
# the weather namespace was registered, PyXB already created the
# binding for the response.
soap_resp = soapenv.CreateFromDOM(domutils.StringToDOM(rxml))
resp = soap_resp.Body().wildcardElements()[0]

fc_return = resp.GetCityForecastByZIPResult()
if fc_return.Success():
print 'Got response for %s, %s:' % (fc_return.City(), fc_return.State())
for fc in fc_return.ForecastResult().Forecast():
when = time.strftime('%A, %B %d %Y', fc.Date().timetuple())
outlook = fc.Desciption() # typos in WSDL left unchanged
low = fc.Temperatures().MorningLow()
high = fc.Temperatures().DaytimeHigh()
print ' %s: %s, from %s to %s' % (when, outlook, low, high)

本文地址:https://codercto.com/soft/d/14902.html

创投42章经

创投42章经

曲凯 / 中信出版集团 / 2018-10-20 / 58.00

《创投42章经》是拥有百万粉丝的微信公众号“42章经”的精选文章合集,全书共分为心法、内功、招式和江湖传奇四部分。 在心法部分,读者可以学到一些创业与投资的底层思维方式;在内功部分,读者可以了解到,投资人看待一家公司经营状况的标准;在招式部分,读者可以看到作者作为一名资深投资人和睿智的观察者,对过去几年主要的公司、模式以及风口的判断;最后的江湖传奇部分,作者通过一些故事,帮助读者更好地理解当......一起来看看 《创投42章经》 这本书的介绍吧!

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具