#111 Make simpleType CF_Enumeration iterable

PyXB 1.1.4
Binding model
PyXB 1.1.3

JAXB has an incredibly useful construct which allows us to take:

<xsd:simpleType name="customerPaymentMethod">

<xsd:restriction base="xsd:string">

<xsd:enumeration value="Credit Card"/>
<xsd:enumeration value="Direct Debit"/>
<xsd:enumeration value="Invoice Only"/>
<xsd:enumeration value="Deferred Payment"/>



and iterate over the values:

for (CustomerPaymentMethod pm: CustomerPaymentMethod.values()) {

Both PyXB and JAXB allow public access to the constants (CustomerPaymentMethod.CREDIT_CARD / customerPaymentMethod.Credit_Card), which is great. If you could make the list of those iterable and part of the public interface then that would be great.


  • Peter A. Bigot

    Peter A. Bigot - 2011-11-28
    • status changed from new to assigned

    Agreed. The tricky bit is if doing this involves adding another reserved symbol ("values" in your example) to the enumeration class to provide access to the iterator. Doing that can collide with enumeration values that end up as class constants.

    Probably the best way is to make the class itself support iteration. I'll experiment and will probably fix this for the next release (whenever that might be).

    Thanks for the suggestion.

  • Peter A. Bigot

    Peter A. Bigot - 2012-02-25
    • status changed from assigned to closed
    • resolution set to fixed

    commit 5255fe507cb2fa07bd9c8587eb0ed2840ae09403
    Author: Peter A. Bigot <pabigot@‌>
    Date: Sat Feb 25 16:29:54 2012 -0600

    trac/111: Make simpleType CF_Enumeration iterable

    Add values, itervalues, items, and iteritems to the enumeration_mixin class,
    forwarding to the underlying CF_Enumeration instance. The value methods
    return the enumeration values, while the item methods return the
    _EnumerationElement instance from which the Python value, Unicode value, and
    tag identifier can be obtained. The item methods are inherited from

    This functionality was available in the CF_Enumeration.elements() method,
    which is now deprecated in favor of items or iteritems.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks