Hi Peter,
Thank you for your reply, it is very useful!
1) For the namespace matter, I wanted to have a default namespace so now it
is working.
2) I did not know that the elements were represented as Python lists
(although it makes sense now).
I will keep playing with PyXB and generateDS and see which one is the most
appropriate for my needs.
I'll come back to you!
Cheers,
2009/11/6 Peter A. Bigot <big...@acm.org>
> > 1) Why the output is different from the input? Am I missing something?
>
> Depends on which difference you mean. PyXB does not preserve (or
> interpret) the document attributes like encoding or standalone. If you want
> to add those, you'd have to use instance.toDOM() and then use the DOM
> methods to modify the document.
>
> Unless you have configured pyxb.utils.domutils.BindingDOMSupport (see
> http://pyxb.sourceforge.net/userref_usebind.html#creating-xml-documents-from-binding-instances),
> it generates a generic prefix for each namespace that is required, which is
> why each element has "ns1" as a prefix. It also will not declare a default
> namespace unless you do something like:
>
>
>
> pyxb.utils.domutils.BindingDOMSupport.SetDefaultNamespace(xml_types.Namespace)
>
> Other than that, they look about the same to me.
>
> > 2) I have also some issues creating the same XML message using the Python
> > binding classes.
>
> >
> > object_one = object_types.Object('A', 'B', 'C')
> > object_two = object_types.Object('A', 'B', 'C')
> > my_objects = object_types.Objects(object_one, object_two)
> >
> > The problem is that I need to create dynamically a message of 10.000
> > objects. Taking this example, it means 10.000 variables, and definitely
> it
> > is not what I want.
>
> I think what you're missing is that the internal elements are present as
> fields (actually, properties) of the containing object, and those elements
> which can appear multiple times are essentially Python lists. So you could
> just as well do:
>
> my_objects = Objects()
> my_objects.Object.append(ObjectType('A', 'B', 'C'))
> my_objects.Object.append(pyxb.BIND('A', 'B', 'C'))
>
> or just extend the existing list value with multiple values at once:
>
> my_objects.Object.extend([ pyxb.BIND('A%d' % (_n,), 'B', 'C') for _n
> in range(0, 9) ])
>
> This pattern could also have been used with the purchase order example:
>
> po.items.append(pyxb.BIND('Lapis necklace', 1, 99.95, partNum='833-AA'))
> po.items.append(pyxb.BIND('Plastic necklace', 4, 3.95, partNum='833-AB'))
>
> Is that more like what you wanted to do?
>
> Peter
>
> Romain CHANU wrote:
>
>> Hi,
>>
>> As I was saying in my previous post, I have some issues to create a XML
>> message with the binding classes.
>>
>> Let's take as an example this XML schema (just the important parts):
>>
>> <xs:element name="Objects">
>> <xs:complexType>
>> <xs:sequence>
>> <xs:element name="Object" type="ObjectType" maxOccurs="unbounded"/>
>> </xs:sequence>
>> </xs:complexType>
>> </xs:element>
>>
>> <xs:complexType name="ObjectType">
>> <xs:sequence>
>> <xs:element name="A" type="xs:string"/>
>> <xs:element name="B" type="xs:string"/>
>> <xs:element name="C" type="xs:string"/>
>> </xs:sequence>
>> </xs:complexType>
>>
>>
>> Then in my Python code (after generating the binding classes):
>>
>> import object_types
>>
>> object_one = object_types.Object('A', 'B', 'C')
>> object_two = object_types.Object('A', 'B', 'C')
>>
>> my_objects = object_types.Objects(object_one, object_two)
>> print my_objects.toxml()
>>
>>
>> This is the only way I have found so far to create my XML message. The
>> problem is that I need to create dynamically a message of 10.000 objects.
>> Taking this example, it means 10.000 variables, and definitely it is not
>> what I want.
>>
>> Could you tell me if there is another way to proceed?
>>
>> Thank you for your help.
>>
>> Romain Chanu
>>
>>
>> PS:
>>
>> The same problem would appear in this example:
>> http://pyxb.sourceforge.net/userref_usebind.html#creating-instances-of-anonymous-typeswith:
>>
>> po.items = pyxb.BIND(pyxb.BIND('Lapis necklace', 1, 99.95,
>> partNum='833-AA'),pyxb.BIND('Plastic necklace', 4, 3.95, partNum='833-AB'))
>> ------------------------------------------------------------------------
>>
>>
>> ------------------------------------------------------------------------------
>> Let Crystal Reports handle the reporting - Free Crystal Reports 2008
>> 30-Day trial. Simplify your report design, integration and deployment - and
>> focus on what you do best, core application coding. Discover what's new with
>> Crystal Reports now. http://p.sf.net/sfu/bobj-july
>> ------------------------------------------------------------------------
>>
>> _______________________________________________
>> pyxb-users mailing list
>> pyxb-users@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/pyxb-users
>>
>>
>
>
>
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day
trial. Simplify your report design, integration and deployment - and focus on
what you do best, core application coding. Discover what's new with
Crystal Reports now. http://p.sf.net/sfu/bobj-july
_______________________________________________
pyxb-users mailing list
pyxb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyxb-users