Hello, I've been checking out PyXB (1.2.4) for a project I'm working on involving the JDF XML schema (http://www.cip4.org/Schema/JDFSchema_1_4a/JDF.xsd) and in general I think PyXB will be a great help, but I'm stumbling over an understanding of how to work with ComplexTypes within the PyXB construct.
Here's a simplified example of something I'm trying to do: So I'm attempting to construct a basic JDF document, and I got about as far as trying to build something that looks like this: <?xml version='1.0' encoding='UTF-8'?> <JDF ID="job123456" Status="Waiting" Type="Combined" xmlns="http://www.CIP4.org/JDFSchema_1_1"> <ResourcePool> <Media Class="Consumable" ID="main" Status="Available"/> <Media Class="Consumable" ID="perf" Status="Available"/> ... </ResourcePool> </JDF> using code like this: import pyxb from print_services.jdf.schema import jdf jdf_obj = jdf.JDF() jdf_obj.ID = "job123456" jdf_obj.Type = "Combined" jdf_obj.Status = "Waiting" media_obj = jdf.Media() media_obj.ID = "main" media_obj.Class = "Consumable" media_obj.Status = "Available" media_obj2 = jdf.Media() media_obj2.ID = "perf" media_obj2.Class = "Consumable" media_obj2.Status = "Available" jdf_obj.ResourcePool.append(media_obj) jdf_obj.ResourcePool.append(media_obj2) Which yields: File "/usr/local/lib/python2.7/site-packages/pyxb/binding/basis.py", line 425, in _CompatibleValue raise pyxb.SimpleTypeValueError(cls, value) pyxb.exceptions_.SimpleTypeValueError: Type {http://www.CIP4.org/JDFSchema_1_1}ResourcePool_ cannot be created from {http://www.CIP4.org/JDFSchema_1_1}Media_r: <print_services.jdf.schema.jdf.Media_r object at 0x109a360d0> So then I thought... ok, maybe I need to create that ResourcePool object: jdf_obj.ResourcePool = jdf.ResourcePool() Nope: File "/usr/local/lib/python2.7/site-packages/pyxb/binding/basis.py", line 1618, in compatibleValue raise pyxb.SimplePluralValueError(self.typeDefinition(), value) pyxb.exceptions_.SimplePluralValueError: Type {http://www.CIP4.org/JDFSchema_1_1}ResourcePool_ cannot be created from {http://www.CIP4.org/JDFSchema_1_1}ResourcePool_: <print_services.jdf.schema.jdf.ResourcePool_ object at 0x1073436d0> Ok, then I went back to the documentation again and started looking into this pyxb.BIND() thing... jdf_obj.ResourcePool.append(pyxb.BIND(media_obj)) Hey, that worked! <?xml version="1.0" ?> <ns1:JDF ID="job123456" Status="Waiting" Type="Combined" xmlns:ns1="http://www.CIP4.org/JDFSchema_1_1"> <ns1:ResourcePool> <ns1:Media Class="Consumable" ID="main" Status="Available"/> </ns1:ResourcePool> </ns1:JDF> Ok, so let's add a second Media element: jdf_obj.ResourcePool.append(pyxb.BIND(media_obj2)) No errors, but ... wait, what? <?xml version="1.0" ?> <ns1:JDF ID="job123456" Status="Waiting" Type="Combined" xmlns:ns1="http://www.CIP4.org/JDFSchema_1_1"> <ns1:ResourcePool> <ns1:Media Class="Consumable" ID="main" Status="Available"/> </ns1:ResourcePool> <ns1:ResourcePool> <ns1:Media Class="Consumable" ID="perf" Status="Available"/> </ns1:ResourcePool> </ns1:JDF> How did I wind up with two ResourcePool elements? Hrmm, ok, maybe I need to construct the ResourcePool element first, and then assign it into the JDF element? rp_obj = jdf.ResourcePool() rp_obj.append(media_obj) rp_obj.append(media_obj2) print rp_obj.toxml() <?xml version="1.0" ?> <ns1:ResourcePool xmlns:ns1="http://www.CIP4.org/JDFSchema_1_1"> <ns1:Media Class="Consumable" ID="main" Status="Available"/> <ns1:Media Class="Consumable" ID="perf" Status="Available"/> </ns1:ResourcePool> Looking promising now! jdf_obj.ResourcePool = rp_obj File "/usr/local/lib/python2.7/site-packages/pyxb/binding/basis.py", line 1618, in compatibleValue raise pyxb.SimplePluralValueError(self.typeDefinition(), value) pyxb.exceptions_.SimplePluralValueError: Type {http://www.CIP4.org/JDFSchema_1_1}ResourcePool_ cannot be created from {http://www.CIP4.org/JDFSchema_1_1}ResourcePool_: <print_services.jdf.schema.jdf.ResourcePool_ object at 0x10453d6d0> Shoot. Maybe I need to do that BIND thing? jdf_obj.ResourcePool = pyxb.BIND(rp_obj) File "/usr/local/lib/python2.7/site-packages/pyxb/binding/basis.py", line 1618, in compatibleValue raise pyxb.SimplePluralValueError(self.typeDefinition(), value) pyxb.exceptions_.SimplePluralValueError: Type {http://www.CIP4.org/JDFSchema_1_1}ResourcePool_ cannot be created from: <pyxb.BIND object at 0x1032a5910> Hrmm......... So, I definitely feel like I'm dancing around the solution, it's in there somewhere, I just don't really understand enough about how these bindings are meant to work and I simply can't find a complete example that describes what I'm trying to do. I'm really hoping that someone can help me out here and point me in the right direction! Thanks so much, --Kevin ------------------------------------------------------------------------------ BPM Camp - Free Virtual Workshop May 6th at 10am PDT/1PM EDT Develop your own process in accordance with the BPMN 2 standard Learn Process modeling best practices with Bonita BPM through live exercises http://www.bonitasoft.com/be-part-of-it/events/bpm-camp-virtual- event?utm_ source=Sourceforge_BPM_Camp_5_6_15&utm_medium=email&utm_campaign=VA_SF _______________________________________________ pyxb-users mailing list pyxb-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/pyxb-users