[英]Howto set “text” value for suds webservice object
Suds seems to have problems parsing the following XSD: Suds似乎在解析以下XSD时遇到问题:
<element name="quantity" minOccurs="1" maxOccurs="1">
<annotation>
<documentation>Quantity of this item that's being ordered.</documentation>
</annotation>
<complexType>
<simpleContent>
<extension base="int">
<attribute name="unitOfMeasure" use="required">
<annotation>
<documentation>
Unit of measurement.
The attribute can have the
following values: PCS - pieces
SEC- seconds BYT - bytes KB -
kilobytes
</documentation>
</annotation>
<simpleType>
<restriction base="string">
<enumeration value="PCS" />
<enumeration value="SEC" />
<enumeration value="BYT" />
<enumeration value="KB" />
</restriction>
</simpleType>
</attribute>
</extension>
</simpleContent>
</complexType>
</element>
The XML is supposed to look like: XML应该看起来像:
<ns0:quantity unitOfMeasure="PCS">1</ns:quantity>
Sadly, I can only set the attribute: 可悲的是,我只能设置属性:
>>> c.factory.create('ns0:item.quantity')
(quantity){
_unitOfMeasure = ""
}
with no possibility to set the "text" value of the XML node. 不可能设置XML节点的“文本”值。
I've tried creating the XML literally: 我尝试过按字面意思创建XML:
element = Element('ns0:quantity')
element.setText("1")
element.set('unitOfMeasure', "PCS")
and passing that as parameter. 并将其作为参数传递。
This looks good in the debug logging (as <ns0:quantity unitOfMeasure="PCS">1</ns0:quantity>
) but the actual request shows this value will be serialized as: 这在调试日志记录中看起来很好(如
<ns0:quantity unitOfMeasure="PCS">1</ns0:quantity>
)但实际请求显示此值将序列化为:
<ns0:quantity />
I'm getting lost here. 我迷路了。 How can I submit this value properly?
如何正确提交此值?
I'm using suds 0.4 我正在使用泡沫0.4
Just found a temporary workaround. 刚刚找到一个临时的解决方法。
The problem also occurs with suds-jurko. suds-jurko也会出现这个问题。 While the pretty-format logging in suds.client shows the XML element, the raw logging in
suds.transport.http
shows that the "plain" output fails to serialize the element. 虽然suds.client中的漂亮格式日志记录显示了XML元素,但
suds.transport.http
中的原始日志记录显示“plain”输出无法序列化该元素。
By enabling client.options.prettyxml = True
this issue is circumvented. 通过启用
client.options.prettyxml = True
可以避免此问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.