Brilliant! Thanks so much for clearing that up for me, I was able to
work from your examples and get things moving again! I definitely was
circling around it but not *quite* grasping what I needed to do.
Also yes, the schema is incredibly complex. Which is another thing I
wanted to ask you about. Are you aware of any reasonably simple ways to
figure out how to "trim the fat" when generating bindings from a schema
like that? The resulting Python code is nearly 90MB in size and takes
something like 15 seconds just to import. It's not a HUGE deal, and I
can manage with it that way if I need to, but if you have any thoughts
or ideas, I'm all ears.
Thanks again!
--Kevin
Peter Bigot wrote:
You've got a pretty complex schema there. Part of the problem is that
it allows you a lot of latitude.
A JDFProcessNode, via the JDFChildElements_ group, includes an
optional ResourcePool element, which in turn is one of the elements of
an unbounded sequence. What this means is that a JDF element can have
multiple ResourcePool elements inside it. That's why you got two of
them in the first attempt: you appended two objects that could be
converted (using pyxb.BIND) into ResourcePool elements by synthesizing
a ResourcePool element from a value that can be content within a
ResourcePool element.
It's also why you can't assign a single ResourcePool directly to the
JDF.ResourcePool attribute: that attribute requires a plural value
(the diagnostic is clearly misleading; the clue is in the exception
name). pyxb.BIND can synthesize the right kind of element given
parameters that could have been passed to that element's
"constructor", but it can't synthesize a list of such elements.
If you only want one, start with one, as you did, and append it to the
list. Then work with that one.
Below is how I might express the code I think you're trying to get:
import jdf.JDF as jdf
jo = jdf.JDF(ID='job123456', Type='Combined', Status='Waiting')
# jo supports multiple ResourcePool elements. Use one, and add it to
# the JDF object.
rp = jdf.ResourcePool()
jo.ResourcePool.append(rp)
# Create a Media and add it to the pool
mo = jdf.Media(ID='main', Class='Consumable', Status='Available')
rp.append(mo)
# Then add another
rp.append(jdf.Media(ID='perf', Class='Consumable', Status='Available'))
print jo.toDOM().toprettyxml()
Or:
jo = jdf.JDF(ID='job123456', Type='Combined', Status='Waiting')
rp = jdf.ResourcePool(jdf.Media(ID='main', Class='Consumable',
Status='Available'),
jdf.Media(ID='perf', Class='Consumable',
Status='Available'))
jo.ResourcePool.append(rp)
Both give you the same XML:
llc[134]$ python test.py
<?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:Media Class="Consumable" ID="perf" Status="Available"/>
</ns1:ResourcePool>
</ns1:JDF>
On Fri, Apr 10, 2015 at 2:55 PM, Kevin Murphy <pkmu...@gmail.com
<mailto:pkmu...@gmail.com>> wrote:
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_
<http://www.CIP4.org/JDFSchema_1_1%7DResourcePool_> cannot be
created from
{http://www.CIP4.org/JDFSchema_1_1}Media_r
<http://www.CIP4.org/JDFSchema_1_1%7DMedia_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_
<http://www.CIP4.org/JDFSchema_1_1%7DResourcePool_> cannot be
created from
{http://www.CIP4.org/JDFSchema_1_1}ResourcePool_
<http://www.CIP4.org/JDFSchema_1_1%7DResourcePool_>:
<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_
<http://www.CIP4.org/JDFSchema_1_1%7DResourcePool_> cannot be
created from
{http://www.CIP4.org/JDFSchema_1_1}ResourcePool_
<http://www.CIP4.org/JDFSchema_1_1%7DResourcePool_>:
<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_
<http://www.CIP4.org/JDFSchema_1_1%7DResourcePool_> 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
<mailto:pyxb-users@lists.sourceforge.net>
https://lists.sourceforge.net/lists/listinfo/pyxb-users
------------------------------------------------------------------------------
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