> Dave,
>
> You kind of understand me correctly - I am wondering whether it is
> possible to retrieve any information from one of the
> xs:simpleType's. How would you retrieve information:
> <simple_type01>Foo</simple_type01> ? I hope it is possible using
> the generateDS-models :-)
Mikki,
Some of the following may be obvious, but I'll try to cover a few
things to try to save you from having to write too many emails.
You can get some information about a simple type. For example,
consider this snippet from the schema I have attached to this message:
<xs:complexType name="complex_type01">
<xs:sequence>
<xs:element name="string_value" type="simple_type01c"/>
<xs:element name="integer_value" type="simple_type02"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="float_value" type="simple_type03"/>
</xs:sequence>
</xs:complexType>
Then, suppose that when I generate my module, I add the command line
option:
--member-specs=dict
You can get and set the value, of course, using the getter and setter
methods:
node.get_string_value()
node.get_integer_value()
node.set_integer_value(25)
And, the generated class will include the following (which I have
reformatted for readability):
class complex_type01(GeneratedsSuper):
member_data_items_ = {
'string_value': MemberSpec_(
'string_value', [
'simple_type01c',
'simple_type01b',
'simple_type01a',
'xs:string'
],
0),
'integer_value': MemberSpec_(
'integer_value', ['simple_type02', 'xs:integer'], 1),
'float_value': MemberSpec_(
'float_value', ['simple_type03', 'xs:float'], 0),
}
You can find the definition of class MemberSpec_ in the generated
module. You have access to (1) the type (name); (2) the base
type it was derived from and the type that was derived from etc; and
(3) an indication of whether it is a container/list (e.g. it's
definition contained maxOccurs="unbounded").
By the way, if you do not need look-up and prefer a list rather than
a dictionary, then use:
--member-specs=list
If you need even more information about the simple type definition,
perhaps it would not be too difficult to extract that directly from
the schema using Lxml and xpath. I've attached a sample script
(simple_types01.py) which should give you a start with that.
Hope this helps. Let me know when I can answer more questions.
Dave
--
Dave Kuhlman
http://www.davekuhlman.org
<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:simpleType name="simple_type01a">
<xs:restriction base="xs:string"/>
</xs:simpleType>
<xs:simpleType name="simple_type01b">
<xs:restriction base="simple_type01a"/>
</xs:simpleType>
<xs:simpleType name="simple_type01c">
<xs:restriction base="simple_type01b">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="9"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="simple_type02">
<xs:restriction base="xs:integer"/>
</xs:simpleType>
<xs:simpleType name="simple_type03">
<xs:restriction base="xs:float"/>
</xs:simpleType>
<xs:complexType name="complex_type01">
<xs:sequence>
<xs:element name="string_value" type="simple_type01c"/>
<xs:element name="integer_value" type="simple_type02"
minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="float_value" type="simple_type03"/>
</xs:sequence>
</xs:complexType>
</xs:schema>
from lxml import etree
def test():
doc = etree.parse('test01.xsd')
root = doc.getroot()
all_root_simpe_types = root.xpath(
'/xs:schema/xs:simpleType',
namespaces=root.nsmap)
print 'All simple types:'
for simple_type in all_root_simpe_types:
print ' name: "%s"' % (simple_type.attrib['name'], )
nodes = root.xpath(
'/xs:schema/xs:simpleType[@name="simple_type01c"]',
namespaces=root.nsmap)
if nodes:
simple_type = nodes[0]
restriction = simple_type.xpath(
'./xs:restriction', namespaces=simple_type.nsmap)[0]
min_value = None
max_value = None
nodes = restriction.xpath(
'./xs:minInclusive[@value]', namespaces=restriction.nsmap)
if nodes:
min_value = nodes[0].attrib['value']
nodes = restriction.xpath(
'./xs:maxInclusive[@value]', namespaces=restriction.nsmap)
if nodes:
max_value = nodes[0].attrib['value']
print 'simple_type01c:'
print ' min_value: %s' % (min_value, )
print ' max_value: %s' % (max_value, )
test()
------------------------------------------------------------------------------
Subversion Kills Productivity. Get off Subversion & Make the Move to Perforce.
With Perforce, you get hassle-free workflows. Merge that actually works.
Faster operations. Version large binaries. Built-in WAN optimization and the
freedom to use Git, Perforce or both. Make the move to Perforce.
http://pubads.g.doubleclick.net/gampad/clk?id=122218951&iu=/4140/ostg.clktrk
_______________________________________________
generateds-users mailing list
generateds-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/generateds-users