FME Version
This course was presented at the FME 2022 User Conference in Vancouver. All of the data is available in the attached articles. For a complete XML Tutorial, see Getting Started with XML.
Introduction
The following tutorial series covers basic approaches for reading and writing both XML and GML. For XML we cover both the XML reader and XMLTemplater / Text File writer approach, and the new XSD based XML reader / writer which uses XML application schemas. For GML, we cover the GML reader / writer in application schema mode, which is the most common approach used by both the generic GML reader / writer and by the GML profile readers / writers such as AIXM and INSPIRE. Overall we try to take a problem-solving approach to make it easier to adapt these workflows to your own datasets and XML/GML profiles.
Background
XML is a form of structured text data that conforms to the open w3c standard. XML formats are commonly used on the web because it is text-based, supports complex data structures and multiple languages. GML, or geography markup language, is meant to support the storage and exchange of geospatial features.
XML formats primarily function as an exchange or messaging format. They carry a lot of schema and do not support spatial indexing, so they are not very efficient for access speed or updates.
Challenge
A big challenge with XML data translation to/from GIS is the fundamental differences in data modeling. GIS typically has relational structures, while XML is typically object-oriented. Practically speaking, this means that XML usually has a highly nested tree structure, and contains series/list features, external references, and multiple geometries. So it may take several tables and rows to model a given XML object in a relational system.
Tutorials
Reading XML with XML and XSD XML Readers
XML is a powerful exchange format that allows for richly structured data models to support data sharing. XML can be used to store large, complex datasets compliant with a specific standard, or can be used to store small messages used in web communications such as HTTP POST bodies.
Most often, XML is read with FME using predefined XML profiles for specific XML formats, or FME's XML reader with Feature Paths. Other approaches to reading include XfMaps, or FME’s Text File reader using XQuery and other XML processing transformers. These approaches are considered advanced and are covered in other articles. In the sections below we will take a look at two styles of XML reading - using the standard XML Reader and using the XSD-Driven XML Reader.
Writing XML with XML and XSD XML Writers
FME has two approaches to writing XML. The first follows building the XML document structure within an XMLTemplater transformer and then writing the result out using the Text File Writer. fme:get-attribute functions are placed within the template at the locations where you want feature attribute values to be merged into the document. This functions much like a mail merge operation, where a letter template receives name and address values from each record to dynamically generate customized messages. Subtemplates can be used to include records from multiple feature types. Finally, the resulting XML document is written out using the Text File Writer.
The second approach consists of writing XML documents conforming to an existing (W3C XSD) XML Schema document. XSD was introduced in 2001, after being acknowledged by the World Wide Web Consortium (W3C) for being a beneficial way of structuring, defining, and restricting elements. Uniquely, in FME, XSD-Driven XML Reading/Writing gives you the advantage of interpreting XML elements as FME features.
The FME feature types must correspond to top-level element declarations, or elements reachable via top-level element declarations, in the XSD Schemas. The top-level element declarations from the XSD Schemas can be identified with the writer’s Feature Paths parameter.
- 2a. XML Writing with XMLTemplater
- 2b. How to Consume and Produce XML using Application Schemas with the XSD-Driven XML Writer
- 2c. Composing XML Documents using the XML Appender Parameters in the XSD-Driven XML Writer
- 2d. Dynamically Constructing the XML Document with the XSD-Driven XML Writer
Reading / Writing GML
GML is a powerful exchange format that allows for richly structured data models that include both attribute properties and geospatial data. It is also an open standard maintained by the OGC - Open Geospatial Consortium that supports open data exchange and data sharing applications around the world.
The overall objective of these GML exercises is to demonstrate a complete example workflow for reading from GML and loading into a database, and then reading the database and writing back to GML, including full validation of the output against the app schema, visual inspection, and inspection of the XML. We use basemap data from UK OS OpenMap Local for the Gloucester area.
- 3a. GML Reading
- 3b. GML Writing
Additional Resources
See the following articles for more information:
Comments
0 comments
Please sign in to leave a comment.