Menu

Extract value from a complextypedefinition

Help
Coderdot
2017-06-09
2017-06-09
  • Coderdot

    Coderdot - 2017-06-09

    I have the following data structure:

    datePrepared <pyxb.bundles.opengis.raw._nsgroup_.TimePositionType object at 0x7fa3df04f610>
    
        _complexTypeDefinition__content 2016-10-19 00:00:00
    

    I failed to extract the dateTime from instance "datePrepared"

    datePrepared is a gml:TimePositionType, schema is as below:

    <complexType name="TimePositionType" final="#all">
         <annotation>
             <documentation>The method for identifying a temporal position is specific to each temporal reference system.  gml:TimePositio    nType supports the description of temporal position according to the subtypes described in ISO 19108.
    

    Values based on calendars and clocks use lexical formats that are based on ISO 8601, as described in XML Schema Part 2:2001. A decimal va lue may be used with coordinate systems such as GPS time or UNIX time. A URI may be used to provide a reference to some era in an ordinal reference system .
    In common with many of the components modelled as data types in the ISO 19100 series of International Standards, the corresponding GML co mponent has simple content. However, the content model gml:TimePositionType is defined in several steps.
    Three XML attributes appear on gml:TimePositionType:
    A time value shall be associated with a temporal reference system through the frame attribute that provides a URI reference that identifi es a description of the reference system. Following ISO 19108, the Gregorian calendar with UTC is the default reference system, but other s may also be used. Components for describing temporal reference systems are described in 14.4, but it is not required that the reference system be described in this, as the reference may refer to anything that may be indentified with a URI.
    For time values using a calendar containing more than one era, the (optional) calendarEraName attribute provides the name of the calendar era.
    Inexact temporal positions may be expressed using the optional indeterminatePosition attribute. This takes a value from an enumeration.</documentation>
    </annotation>
    <simpleContent>
    <extension base="gml:TimePositionUnion">
    <attribute name="frame" type="anyURI" default="#ISO-8601"/>
    <attribute name="calendarEraName" type="string"/>
    <attribute name="indeterminatePosition" type="gml:TimeIndeterminateValueType"/>
    </extension>
    </simpleContent>
    </complexType>

    The schema for TimePositionUnion type is as following:

      <simpleType name="TimePositionUnion">
        <annotation>
            <documentation>The simple type gml:TimePositionUnion is a union of XML Schema simple types which instantiate the subtypes for temporal position described in ISO 19108.
    

    An ordinal era may be referenced via URI. A decimal value may be used to indicate the distance from the scale origin . time is used for a position that recurs daily (see ISO 19108:2002 5.4.4.2).
    Finally, calendar and clock forms that support the representation of time in systems based on years, months, days, hours, minutes and seconds, in a notation following ISO 8601, are assembled by gml:CalDate</documentation>
    </annotation>
    <union memberTypes="gml:CalDate time dateTime anyURI decimal"/>
    </simpleType>

    I tried following Python code to extract the dateTime value from TimePositionType as below:
    

    datePrepared = formInformation.datePrepared
    frame = getattr(datePrepared, "")
    print(dir(datePrepared))

    all = datePrepared._element()

    print(dir(all))
    content = datePrepared.orderedContent[0]
    print(dir(content))
    value = datePrepared.frame
    print(dir(value))
    orderedContent = datePrepared.indeterminatePosition
    print(dir(orderedContent))

    The following definitly is not correct:

    print(formInformation.datePrepared.wildcardElements)
    print(formInformation.datePrepared.month)

    print(formInformation.datePrepared.year)
    print(formInformation.datePrepared.month)

    print(formInformation.datePrepared.day)
    print(formInformation.datePrepared.hour)
    print(formInformation.datePrepared.min)

    How could I extract the dateTime value from a gml:TimePositionType, which contains a gml:TimePositionUnion simple type, which contains a dateTime.

    Best wishes,

    Thanks all of you

     
  • Peter A. Bigot

    Peter A. Bigot - 2017-06-09

    TimePositionType is a complex type with simple content, meaning that it is a basic value that's annotated with attributes. Because you need to access the attributes like calendarEraName from the instance, you have to use the value() method on the instance to access the basic value.

    Example schema:

    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema
        targetNamespace="URN:test"
        xmlns:gml="http://www.opengis.net/gml/3.2"
        xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="datePrepared" type="gml:TimePositionType"/>
    </xs:schema>
    

    Build with:

    PYXB_ARCHIVE_PATH='&pyxb/bundles/opengis//:&pyxb/bundles/common//' \
        pyxbgen -u tp.xsd -m tp
    

    Test with:

    import tp
    
    doc = '<datePrepared xmlns="URN:test">2017-01-01T00:00:00Z</datePrepared>'
    dp = tp.CreateFromDocument(doc)
    date = dp.value()
    print type(date)
    print date
    

    which produces:

    lilith[43]$ python utp.py 
    <class 'pyxb.binding.datatypes.dateTime'>
    2017-01-01 00:00:00+00:00
    

    This interface is documented here which I admit is not easy to find.

     

Log in to post a comment.