[xsd-users] How to get Objects for Elements referenced by xlink:href

Boris Kolpackov boris at codesynthesis.com
Fri Aug 8 04:39:13 EDT 2008


Hi Jan,

Jan Klimke <jan.klimke at hpi.uni-potsdam.de> writes:

> <?xml version="1.0" encoding="utf-8"?>
> <wfs:FeatureCollection numberOfFeatures='4' 
> xmlns:app="http://www.deegree.org/app" 
> xmlns:wfs="http://www.opengis.net/wfs" 
> xmlns:xlink="http://www.w3.org/1999/xlink" 
> xmlns:gml="http://www.opengis.net/gml" 
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
> 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://www.opengis.net/wfs http://schemas.opengis.net/wfs/1.1.0/wfs.xsd">
>  <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




More information about the xsd-users mailing list