考虑到该模式:
<xs:element name="person">
<xs:complexType>
<xs:sequence>
<xs:element name="firstname" type="xs:string"/>
<xs:element name="lastname" type="xs:string"/>
</xs:sequence>
<xs:anyAttribute/>
</xs:complexType>
</xs:element>在运行pyxb -u <filename> -m person命令之后,如何使用生成的绑定创建具有任意属性的XML。
import person
p = person()
p.firstname = 'bob'
p.lastname = 'bobbington'
#I want behavior like this
p.middlename = 'bobby'
#I would settle for behavior like this:
p.add_attribute( 'middlename', 'bobby' )
#Heck*, I'd even settle for:
temp_attr = pyxb.AttributeUse( name, value, blah, blah, blay )
p._AttributeMap.update( temp_attr.name(), temp_attr )但是,无论我如何尝试,在调用p.toxml()时,我都无法获得显示临时属性的方法。
这不支持吗?还是我忽略了什么?
编辑:删除亵渎。
编辑:做了一个工作(语法和变量名称是很遥远的,但希望它足以帮助其他人弄清楚)
class PersonType():
'''
regular generated PersonType stuff here
'''
def add_attribute(self, name, value):
t = pyxb.blahblahblah._AttributeUse(
pyxb.blahblahblah._ExtendedName( None, attr_name),
attr_name,
pyxb.blahblah.StringDataType)
t.setValue(self, value) # or maybe _setValue
self._AttributeMap[t.name()] = t发布于 2014-06-06 01:33:06
如果复杂类型支持通配符属性,则该类型的实例有一个方法wildcardAttributeMap(),它是从扩展名称到表示属性值的unicode字符串的映射。目前每个这张票都没有公共API来操作这个映射,尽管您可能可以手动操作。
在回顾您的问题的基础上,我添加了这张票,它确认即使您将通配符属性放入映射中,它们也不会出现在生成的XML中。
真对不起。看来是时候再做一轮PyXB错误修复了。
https://stackoverflow.com/questions/24049912
复制相似问题