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

精通正则表达式

精通正则表达式

Jeffrey E. F. Friedl / 余晟 / 电子工业出版社 / 2007 / 75

随着互联网的迅速发展,几乎所有工具软件和程序语言都支持的正则表达式也变得越来越强大和易于使用。本书是讲解正则表达式的经典之作。本书主要讲解了正则表达式的特性和流派、匹配原理、优化原则、实用诀窍以及调校措施,并详细介绍了正则表达式在Perl、Java、.NET、PHP中的用法。 本书自第1 版开始着力于教会读者“以正则表达式来思考”,来让读者真正“精通”正则表达式。该版对PHP的相关内容、Ja......一起来看看 《精通正则表达式》 这本书的介绍吧!

HTML 编码/解码
HTML 编码/解码

HTML 编码/解码

RGB HSV 转换
RGB HSV 转换

RGB HSV 互转工具