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)
http://pyxb.sourceforge.net/ PyXB (“pixbee”) is a pure Python package that generates Python source code for classes that correspond to data structures defined by XMLSchema. The generated classes suppo
我有以下XSD,我正在从中生成JAXB绑定…(只为这个问题留下了相关部分):
关于xml名称空间,我有几个问题,我将用以下三段代码来解释: 1-非常简单的XML架构: 2-使用新创建的XML架构的XML: 3-与上述两者没有关系的另一段代码: 为什么我们总是声明像xmlns=“http://www.w3.org/2001/xmlschema”和xmlns:xsi=“http://www.wc3.org/2001/xmlschema-instance”这样的名称空间,但没有给
if绑定 if绑定应用在页面元素中,并通过表达式判断是否为元素添加子元素的绑定。if绑定在功能上非常像visible绑定,但在实现上却有很大的不同。visible绑定是为元素添加css样式来控制元素是否显示,if绑定是控制元素的字元素,如果表达式为true,则为元素添加子元素,否则清空子元素。 示例代码: //.W片段 <label> <input type="checkbox" bind-c
诸如本地变量、实例变量、self一类的实体……或者说所有于对象绑定的名称。我们把他们称为绑定(bindings)。 下面内容摘自紫苏的博客,该文对我们的讨论很有意义。 在计算机科学中,“绑定”(Binding)一词是指一个更复杂、更大型的物件的引用的创建。例如当我们编写了一个函数,这个函数名就绑定了该函数本体,我们可以通过函数名来引用并调用该函数,这被称为名称绑定;又如当Ruby通过API去调用了
问题内容: 在Python中,有没有办法绑定未绑定的方法而不调用它? 我正在编写一个程序,对于某个类,我决定将所有按钮的数据分组为类级别的元组列表是一件好事,如下所示: 问题是,因为所有的值r都是未绑定方法,所以我的程序爆炸得很厉害,我哭了。 我正在网上寻找解决方案,该方案应该是一个相对直接,可解决的问题。不幸的是我找不到任何东西。现在,我正在解决此问题,但是没有人知道是否存在一种干净,健康,Py
attr绑定是用来为html元素绑定属性值的,这种绑定非常有用,例如我们需要想一个元素添加title属性,或者为img标签添加src属性。 示例代码: //.W片段 <a bind-attr="{ href: url, title: details }"> Report </a> //js片段 this.url=justep.Bind.observable("year-end.html"),
submit绑定只能用在form元素中,当form提交的时候被触发,并且默认阻止form的提交。因此我们通常在submit的处理函数中以ajax的方式提交form表单。 示例代码: //.W片段 <form bind-submit="doSomething"> ... form contents go here ... <button type="submit">Submit</butt
with绑定用来创建一个绑定上下文,在子元素内的所有绑定都在这个上下文中进行。 示例代码: //.W片段 <h1 bind-text="city"> </h1> <p bind-with="coords"> Latitude: <span bind-text="latitude"> </span>, Longitude: <span bind-text="longitude"> </span