[xsd-users] Resolving xlinks in a GML file

Laurence Davies laurence.davies at unsw.edu.au
Thu Jun 25 22:17:42 EDT 2015


(Resent with a subject line)

Hi Boris,

I'm attempting to write some general code for resolving xlinks in a GML document. They typically use the gml:id attribute, but there is the case where a URN or URL will be used.

An example of a URL link:

<geo:associatedDocument>
    <geo:Document gml:id="SINEX_2">
        <geo:type>SINEX</geo:type><geo:createdDate>2015-03-20Z</geo:createdDate><geo:receivedDate></geo:receivedDate>
        <geo:custodian xlink:href="#DrJohnDawsonGA"/>
        <geo:body>
            <geo:fileReference xlink:href="ftp://ftp.ga.gov.au/geodesy-outgoing/gnss/solutions/apref/apr18287.snx" />
        </geo:body>
    </geo:Document>
</geo:associatedDocument>

Another example, containing a URL and a gml:id href:

<geo:PositionTimeSeries gml:id="ID_PTS_1" srsName="http://www.opengis.net/gml/srs/epsg.xml#4938" srsDimension="3">
    <geo:atNode xlink:href="#NODE_1" />
    <geo:Status>
        <geo:currentStatus>
            <gml:validTime>
                <gml:TimeInstant gml:id="ID_PTS_STATUS_1">
                    <gml:timePosition>2013-11-04Z</gml:timePosition>
                </gml:TimeInstant>
            </gml:validTime>
            <geo:statusCode codeSpace="">Authoritative</geo:statusCode>
        </geo:currentStatus>
    </geo:Status>
    ...
</geo:PositionTimeSeries>


I found a relevant solution you provided in 2008 on this subject in the email below that covers the gml:id case but not the latter. Would you know what call I would need to make to resolve a URL and, if possible, a URN?


Hi Jan,

Jan Klimke <jan.klimke at hpi.uni-potsdam.de<http://codesynthesis.com/mailman/listinfo/xsd-users>> writes:

> <?xml version="1.0" encoding="utf-8"?>
> <wfs:FeatureCollection numberOfFeatures='4'
> xmlns:app="http://www.deegree.org/app"<http://www.deegree.org/app%22>
> xmlns:wfs="http://www.opengis.net/wfs"<http://www.opengis.net/wfs%22>
> xmlns:xlink="http://www.w3.org/1999/xlink"<http://www.w3.org/1999/xlink%22>
> xmlns:gml="http://www.opengis.net/gml"<http://www.opengis.net/gml%22>
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"<http://www.w3.org/2001/XMLSchema-instance%22>
> xsi:schemaLocation="http://www.deegree.org/app
> http://servername:8080/deegree-wfs/services?SERVICE=WFS&amp;VERSION=1.1.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=app:User&amp;NAMESPACE=xmlns(app=http://www.deegree.org/app<http://servername:8080/deegree-wfs/services?SERVICE=WFS&amp;VERSION=1.1.0&amp;REQUEST=DescribeFeatureType&amp;TYPENAME=app:User&amp;NAMESPACE=xmlns%28app=http://www.deegree.org/app>)
> http://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd"<http://schemas.opengis.net/wfs/1.1.0/wfs.xsd%22>>
>  <gml:featureMember>
>    <app:User gml:id="USER_133">
>      <app:id>133</app:id>
>      <app:name>Friedrich Engels2</app:name>
>      <app:color>
>        <app:Color gml:id="COLOR_70">
>          <app:id>70</app:id>
>          <app:red>1.0</app:red>
>          <app:green>0.0</app:green>
>          <app:blue>0.0</app:blue>
>          <app:alpha>1.0</app:alpha>
>        </app:Color>
>      </app:color>
>    </app:User>
>  </gml:featureMember>
>  <gml:featureMember>
>    <app:User gml:id="USER_134">
>      <app:id>134</app:id>
>      <app:name>Friedrich Engels</app:name>
>      <app:color xlink:href="#COLOR_70"/>
>    </app:User>
>  </gml:featureMember>
> </wfs:FeatureCollection>
>
> As you can see, the second user has a xlink reference in its <app:color>
> property referencing "COLOR_70" which appeared "earlier" in the
> document. My problem is now to obtain a reference to  the Color object
> for the "USER_134" object. How can i resolve such inner document xlink
> references ?

I checked the GML schema and the gml:id attribute is of xsd:ID type. If
all href attributes always refer one of those gml:id attributes then this
is pretty simple to do:

std::string href = ... // contains "COLOR_70", without #
color_t& color = ... // reference to an object containing href

xml_schema::idref ref (href, 0, &color);
xml_schema::type* p = ref.get (); // p points to the object with ID COLOR_70

// Now you can use static_cast (if you are sure about the type of p) or
// dynamic_cast (if you are not) to cast it to the Color_t type.

If you cannot assume that all href attributes point to one of the gml:id
attributes (or other attributes as long as they are of the xsd:ID type)
then things get a bit more complex. Let me know if this is the case and
I will describe how this can be done.

Boris

Kind regards,

Laurence Davies
____________________
Research Assistant in eGeodesy
CRC-SI, UNSW
Desk phone: (03) 8636 2373
Mobile: 0427 519 289


More information about the xsd-users mailing list