Dashboard > OWS Documenation > TOC > WFS > Interpreting XML-GML and XSD-Schema
Interpreting XML-GML and XSD-Schema Log In | Sign Up   View a printable version of the current page.

Added by David Blasby , last edited by David Blasby on May 27, 2005  (view change)
Labels: 
(None)

What is XML?

What is XML (eXtensible Markup Language)?

An XML document is a structured text file that both contains and describes your data. The document can be easily read and interpreted by computer programs.

XML looks very much like HTML and is used in all sorts of web applications and data formats.

For more information visit the wikipedia , the offical WC3 site, a WC3 summary of XML, or a summary of xml.

Example of an XML document

<?xml version="1.0" encoding="UTF-8"?>
<Person>
     <Name>David Blasby</Name>
     <Age>34</Age>
     <City>New York</City>
     <Country>USA</Country>
     <BirthDate calendar="julian">
            <Year>1969</Year>
            <Month>June</Month>
     </BirthDate>
</Person>

The above XML document describes a single "Person" object. This object contains the following properties:

Property Name Value
Name David Blasby
Age 34
City New York
Country USA
BrithDate Another object describing "June, 1969"

A typical XML document contains:

  • matching start and end tag i.e. "<Name>" and "</Name>"
  • tags that define properties of an object - the property's value is contained within the tag (either text like "David Blasby" or other tags)
  • tag attributes add extra information about a propery's value i.e. calendar="julian"

What is GML?

What is GML (Geographic Markup Language)?

A GML document is a type of XML document that represents Geographic information.

$body

According to the OGC, the Geography Markup Language (GML) is an XML encoding for the transport and storage of geographic information, including both the spatial and non-spatial properties of geographic features.
This specification defines the XML Schema syntax, mechanisms, and conventions that

  • Provide an open, vendor-neutral framework for the definition of geospatial application schemas
    and objects;
  • Allow profiles that support proper subsets of GML framework descriptive capabilities;
  • Support the description of geospatial application schemas for specialized domains and information communities;
  • Enable the creation and maintenance of linked geographic application schemas and datasets;
  • Support the storage and transport of application schemas and data sets;
  • Increase the ability of organizations to share geographic application schemas and the information they describe.

Implementers may decide to store geographic application schemas and information in GML, or they may decide to convert from some other storage format on demand and use GML only for schema and data transport.

The goals of GML are to provide a means of encoding spatial information for both data transport and data storage, especially in a wide-area Internet context;

  • be sufficiently extensible to support a wide variety of spatial tasks, from portrayal to analysis;
  • allow for the efficient encoding of geo-spatial geometry (e.g. data compression);
  • provide easy-to-understand encodings of spatial information and spatial relationships, including those defined by the OGC Simple Features model;
  • be able to readily link and encode spatial (geometric) elements to other spatial or non-spatial elements.
  • provide a set common geographic modeling objects to enable interoperability of independently developed applications.

For the current best introduction to GML, check the GML entry on the wikipedia .

Why use GML?

Why use GML?

1. It is a well-defined and well-known OGC standard
2. It is extreamly good at capturing and describing simple and very complex Geographic objects and relationships
3. There are many existing GIS products that can create and manipulate GML
4. Products that support GML are able to interoperate with other each other
5. There are many pre-existing tools that can read, write, manipulate, and validate XML documents.
6. There are no other interchange format that is as expressive and supported as GML
7. WFS servers expect GML as input and generate GML as output

Example of a GML document

<?xml version="1.0" encoding="UTF-8"?>
<wfs:FeatureCollection xmlns:wfs="http://www.opengis.net/wfs"
                       xmlns:topp="http://www.openplans.org/topp" 
                       xmlns:gml="http://www.opengis.net/gml" 
                       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                       xsi:schemaLocation=
		                 "http://www.openplans.org/topp ...see below...
		                  http://www.opengis.net/wfs WFS-basic.xsd">

	<gml:boundedBy>
		<gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
			<gml:coordinates decimal="." cs="," ts=" ">
                                  -134.16582,59.10523 -133.5789,59.99972
                        </gml:coordinates>
		</gml:Box>
	</gml:boundedBy>

	<gml:featureMember>
		<topp:bc_2m_lakes fid="bc_2m_lakes.3">
			<topp:the_geom>
                               <gml:MultiPolygon srsName="http://www.opengis.net/gml/srs/epsg.xml#4326">
                                    <gml:polygonMember>
                                             ... large polygon definition removed ...
                                    </gml:polygonMember>
                               </gml:MultiPolygon>
                        </topp:the_geom>
			<topp:LAKE_ID>3467</topp:LAKE_ID>
			<topp:AREA>4672.3</topp:AREA>
			<topp:NAME>Lake Brandy</topp:NAME>
			<topp:AVG_DEPTH>15.5</topp:AVG_DEPTH>
		</topp:bc_2m_lakes>
	</gml:featureMember>	

</wfs:FeatureCollection>

This XML document is an example of "GetFeatures" response from a WFS server. Its content is described in more detail in later sections, but this document contain the data for single "topp:bc_2m_lake" feature. The document is composed of:

  • reference to schemas that describe the format of this XML/GML document (see below)
  • a <FeatureCollection> tag that contains feature object
  • a single "bc_2m_lakes" feature object that contains these properties:
    • a polygon geometry ("the_geom")
    • a LAKE_ID with value 3467
    • an AREA with value 4672.3
    • a NAME with value "Lake Brandy"
    • a AVG_DEPTH with value 15.5
What do the "<prefix:elementName>" tags mean?

By using a namespace prefix in a tag, you uniquely identify the tag and its meaning. For example a "<width>" tag could have several different meanings. The namespace prefix uniquely links the tag to a schema which, in turn, defines exactly what it means and how to use it.

$body

It is recommended to always use tags in the "<prefix:elementName>" format and define the namespace near the start of your document using the xmlns attribute:

<abc xmlns:myns="http://unique.url.com/location"
     schemaLocation="http://unique.url.com/location mySchema.xsd">

This says that the short form of the "http://unique.url.com/location" namespace is the "myns" prefix and its meaning is defined in the "mySchema.xsd" schema file.

NOTE: The schemaLocation attribute allows you to optionally give the location of schemas for several namespaces in the format "namespace1 SchemaURL1 namespace2 SchemaURL2".

NOTE: You may specify a default namespace for your document so that un-prefixed tag (like "<mytag>") will be in the default namespace. Since many of the XML documents will have tags in many different namespaces, using the default namespace is not recommended since it can lead to confusion.

XSD - Describing the XML document

What is XSD (XML Schema Definition)?

An XSD document is an XML document that describes the structure and content of another XML document. It is used to both valiadate an XML document and used by programs that read the XML document to understand the content.

Visit the wikipedia page or a tutorial.

WFS Response Schema - GML schema, WFS schema, and the "Application Schema"

The "Example of a GML document", shown above, shows a typical XML response from a WFS server. The actual schema of this document is built from three distinct schemas - the GML schema, the WFS schema, and an application specific schema.

Schema Description of what concepts the schema defines
GML This schema gives basic definitions including (1) What a 'generic' GML Feature is (2) What a collection of GML Features is and (3) how a geometry is represented in XML
WFS Defines the overall content of the response - tags like <FeatureCollection> and <featureMember> - and what type of content is allowed in them.
Application Schema Defines what a particular type of feature should look like (i.e. its set of property names and types)

The GML schema defines some basic concepts, the WFS schema extends these concepts, and the Application Schema further extends the concepts. When we look at the WFS response for GetFeatures, we will see:

  • The GML schema defines the generic "look" of a GML Feature (a gml:_Feature)
  • The GML schema defines that a gml:_FeatureCollection is a set of "featureMember"s
  • The GML schema defines a "featureMember" as containing a generic Feature (a gml:_Feature)
  • The WFS schema defines that the response will be a gml:_FeatureCollection
  • The Application Schema defines the actual "look" (property names and types) of the Features being returned.

NOTE: The above is a simplification, please read the GML Specification for more details.

Example XSD Application Schema for a WFS response document

Here is the XSD document that describes the topp namespace tags in the above example GML document:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema   targetNamespace="http://www.openplans.org/topp"
             xmlns:topp="http://www.openplans.org/topp"
             xmlns:gml="http://www.opengis.net/gml" 
             xmlns:xs="http://www.w3.org/2001/XMLSchema" 
             elementFormDefault="qualified" 
             attributeFormDefault="unqualified" 
             version="1.0">

<xs:import namespace="http://www.opengis.net/gml"                 
              schemaLocation="feature.xsd"/>

<xs:complexType xmlns:xs="http://www.w3.org/2001/XMLSchema" name="bc_2m_lakes_Type">
      <xs:complexContent>
         <xs:extension base="gml:AbstractFeatureType">
         <xs:sequence>
           <xs:element name="the_geom"  minOccurs="0" nillable="true" type="gml:MultiPolygonPropertyType"/>
           <xs:element name="LAKE_ID"   minOccurs="0" nillable="true" type="xs:int"/>
           <xs:element name="AREA"      minOccurs="0" nillable="true" type="xs:double"/>
           <xs:element name="NAME"      minOccurs="0" nillable="true" type="xs:string"/>
           <xs:element name="AVG_DEPTH" minOccurs="0" nillable="true" type="xs:double"/>
         </xs:sequence>
         </xs:extension>
      </xs:complexContent>
</xs:complexType>

<xs:element name='bc_2m_lakes' type='topp:bc_2m_lakes_Type' substitutionGroup='gml:_Feature'/>

</xs:schema>

This XSD is in three parts:
1. setup (define the namespace thats going to be described and import the definition of other namespaces)
2. defines the "topp:bc_2m_lakes_Type"
3. defines that elements like "<topp:bc_2m_lakes>" are of type "topp:bc_2m_lakes_Type" and can be used where ever a 'gml:_Feature' is required.

Item Meaning
targetNamespace="http://www.openplans.org/topp" This document is describing the schema for the "http://www.openplans.org/topp" namespace
<xs:import namespace="http://www.opengis.net/gml" schemaLocation="feature.xsd"/> Loads in the GML schema definitions
<xs:complexType ... name="bc_2m_lakes_Type"> This starts the definition of the Type called "bc_2m_lakes_Type".
<xs:extension base="gml:AbstractFeatureType"> This indicates that the "bc_2m_lakes_Type" has a few properties predefined for it by the gml:AbstractFeatureType type (see below). This is much like "extends" in normal object-oriented programming.
<xs:element name="..." .../> These define the property names and types that a bc_2m_lakes_Type object will have.
<xs:element name='bc_2m_lakes' type='topp:bc_2m_lakes_Type' substitutionGroup='gml:_Feature'/> This means that any <topp:bc_2m_lakes> tag found in a document will conform to the bc_2m_lakes_Type definition. Secondly, the "substituationGroup" means that a <topp:bc_2m_lakes> tag can be used wherever a generic gml feature ("gml:_Feature") is required - this is very important because it connects your specific object definition to the concept of a gml feature. This is much like "implements" in normal object-oriented programming.

In java one might write this:

import gml.AbstractFeatureType ;
import gml._Feature;
import gml.MultiPolygonPropertyType;
import xml.xs_int;
import xml.xs_double;
import xml.xs_string;

public class bc_2m_lakes_Type extends AbstractFeatureType implements _Feature
{
       MultiPolygonPropertyType the_geom; // optional, null okay
       xs_int                   LAKE_ID;  // optional, null okay
       xs_double                AREA;     // optional, null okay
       xs_string                NAME;     // optional, null okay
       xs_double                AVG_DEPTH;// optional, null okay
}

//see below
public class AbstractFeatureType implements _Feature
{
   xs_string  Description;// optional
   xs_string  Name      ; // optional 
   gml_Box    boundedBy ; // optional 
}
The AbstractFeatureType

GML predefines these properties for Features:

  • gml:Description (optional) of type string
  • gml:Name (optional) of type string
  • gml:boundedBy (optional) of type gml:Box (or null)

NOTE: These tags are in the GML namespace (not the application namespace):

<topp:bc_2m_lakes fid="bc_2m_lakes.3">
	...
	<topp:LAKE_ID>3467</topp:LAKE_ID>
	...
        <gml:Description>This is a lake</gml:Description>
        <gml:Name>Lake Brandy</gml:Name>
        <gml:boundedBy>...</gml:boundedBy>
</topp:bc_2m_lakes>
The xs:element tag
<xs:element name=... minOccurs=... maxOccurs=.. nillable=true|false type=... >

This defines a tag with a particular name, a particular type, if the tag is allowed to be empty (null), and if the tag is optional or not.
Typically, for a Feature, we would see :
maxOccurs=1 (the default) and minOccurs=0 -> the property is optional
maxOccurs=1 (the default) and minOccurs=1 (default) -> the property is required

What is the GML representation of a Geometry?

Its outside the scope of this document to do into details of this. You can see examples in future sections.
Please consult the GML specification here for full details.

Anonymous

G2kivC <a href="http://ptvktbpzegya.com/">ptvktbpzegya</a>, [url=http://ancrtesuqcbb.com/]ancrtesuqcbb[/url], [link=http://fbehbbcfxksi.com/]fbehbbcfxksi[/link], http://sceanvlctoko.com/

Add Comment
Powered by a free Atlassian Confluence Open Source Project License granted to uDig. Evaluate Confluence today.
Powered by Atlassian Confluence 2.7.1, the Enterprise Wiki. Bug/feature request - Atlassian news - Contact administrators
User-friendly Desktop Internet GIS