Look more carefully at the schema.  You're creating an MD_ScopeCode
element, which is type gco:CodeListValue_Type.  hierarchyLevel is a plural
element with underlying type MD_ScopeCode_PropertyType.  That type in turn
attaches an attribute to an element that contains multiple MD_ScopeCode
elements.

So you need something like:

import pyxb
import pyxb.bundles.opengis.iso19139.v20070417.gmd as gmd
md = gmd.MD_Metadata()
scope_code = gmd.MD_ScopeCode('dataset',
                              codeList='uglystring',
                              codeListValue='dataset')
# Can't add one of these in isolation
try:
    md.hierarchyLevel.append(scope_code)
except pyxb.ValidationError:
    pass
# Instead, make it a member
scpt = gmd.MD_ScopeCode_PropertyType().append(scope_code)
md.hierarchyLevel.append(scpt)

It would help if it were easier to see what type of element the plural
binding expects; it's a private attribute, so you can get to it this way:

>>> md.hierarchyLevel._PluralBinding__elementBinding.typeDefinition()
<class 'pyxb.bundles.opengis.raw._nsgroup_.MD_ScopeCode_PropertyType'>

Take advantage of tab completion in the Python shell to expose the contents
of attributes like this.

I've added ticket 220 to improve the interface to this information.

Peter


On Wed, Nov 13, 2013 at 11:05 AM, Ricardo Filipe Soares Garcia da <
ricardo.garcia.si...@gmail.com> wrote:

> Hi list
>
> I am trying to create a gmd:MD_Metadata instance. I am using pyxb v1.2.3
> as downloaded from pypi. I am using the opengis bindings.
>
> My ultimate goal is to create an ISO19139 compliant MD_Metadata XML for
> some satellite imagery datasets. This metadata will then be submitted to an
> OGC compliant  catalogue (CSW) server.
>
> I am currently struggling to define the hierarchyLevel for my MD_Metadata
> element. It must be defined as an MD_ScopeCode element with the 'dataset'
> value. I am getting the following error:
>
> >>> import pyxb.bundles.opengis.iso19139.v20070417.gmd as gm
> >>> md = gmd.MD_Metadata()
> >>> scope_code = gmd.MD_ScopeCode('dataset', >>> codeList=''
> http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#MD_ScopeCode',
> codeListValue='dataset')
> >>> md.hierarchyLevel
> <pyxb.binding.content._PluralBinding at 0x591ad10>
> >>> md.hierarchyLevel.append(scope_code)
> SimpleTypeValueError: Type {
> http://www.isotc211.org/2005/gmd}MD_ScopeCode_PropertyType cannot be
> created from {http://www.isotc211.org/2005/gco}CodeListValue_Type:
> <pyxb.bundles.opengis.raw._nsgroup_.CodeListValue_Type object at 0x590dd90>
>
> How can insert the hierarchyLevel information into my MD_Metadata object?
>
> Thanks in advance
>
> --
> ___________________________ ___ __
> Ricardo Garcia Silva
>
>
> ------------------------------------------------------------------------------
> DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
> OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
> Free app hosting. Or install the open source package on any LAMP server.
> Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
> http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
> _______________________________________________
> pyxb-users mailing list
> pyxb-users@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/pyxb-users
>
>
------------------------------------------------------------------------------
DreamFactory - Open Source REST & JSON Services for HTML5 & Native Apps
OAuth, Users, Roles, SQL, NoSQL, BLOB Storage and External API Access
Free app hosting. Or install the open source package on any LAMP server.
Sign up and see examples for AngularJS, jQuery, Sencha Touch and Native!
http://pubads.g.doubleclick.net/gampad/clk?id=63469471&iu=/4140/ostg.clktrk
_______________________________________________
pyxb-users mailing list
pyxb-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/pyxb-users

Reply via email to