Tutorial: Getting Started with XML

Liz Sanderson
Liz Sanderson

FME Version

Introduction

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, and support 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. To learn more about XML, see the W3Schools Introduction to XML. 
 

Key Terms

The following is a table that highlights the different terms FME uses to describe the same thing in both a database and an XML document. 
FMEDatabaseXML
FeatureRecordElement
AttributeFieldElement
TraitSubfieldAttribute
ListComma-delimited FieldSeries
ReferenceRelationParent
  • Application Schema: XML schema definition that defines the object structures that are available and can be used to validate a dataset. Typically an .xsd file.
  • Feature Path: Match expressions that specify which XML elements in the dataset should be extracted into features. These match expressions are also referred to as ‘elements to match’. They can contain an XML element name or path from dataset root to the element.
  • Namespace: A method for qualifying element and attribute names used in XML documents by associating element prefixes with URI references. For example, prefix:element where prefix is defined by xmlns:prefix = “myurl.com”
  • Parent: Element that holds other related elements (children).
  • Profile: Sets of standardized application schemas that are grouped together.
  • Root: The first named tag of every XML file and is a container for all other elements
  • XML: EXtensible Markup Language. Typically an .xml file.
 

Some XML Basics

Let’s start by considering a building.
  • A building has address and location details
  • It contains rooms
  • Rooms contain walls
How would this building be modeled in XML? XML is nested, which makes the hierarchical relationship between buildings, rooms, and walls easy to model:
Initial.png

An XML file is comprised of many TAGS, represented by pairs of angle brackets < >. These TAGS represent XML elements.
  1. The first element may contain information such as the XML version and encoding. It’s optional, but if it exists, it’s present at the start of an XML file.
  2. Next is the ROOT element. The ROOT is the first-named tag of every XML file and is a container for all other elements. In this case, the ROOT element is named Dataset.
  3. Within the Dataset are branches to CHILD elements. This Building element, named Surrey Head Office, is a CHILD of the Dataset. The Building, in turn, has many of its own children, and so on. 
 

The FME Approach

In order to support transformations from one data structure to the other, FME needs to model complex data objects. There are a number of element types in XML that are not common in GIS and so require modeling conventions in FME so that the data can be read and written. FME can convert any XML element into an FME feature.

Consider the building XML file described above. Every single XML element could become an FME feature. Or, we could work with the Building only, or work with the individual rooms or walls. It all depends on what the requirements of the transformation are.

Here are a couple of examples of FME transforming XML data:
Image1.jpeg


Image2.jpeg


Feature Paths and flattening help convert any XML element into an FME feature. Feature paths allow you to query XML by defining the node in the XML structure from which you want to extract features. Flattening allows you to convert the nested structures within the selected XML element into fields in the form of parent.child. Parent ids can be recorded so you can build associations. This approach replaces the need to use scripts (xfmaps) or text processing to read XML. There is also a tree control that helps define feature paths automatically.

Note that FME also offers other advanced options for XML processing that allows XML documents to be updated directly rather than flattened or converted to FME features. These alternative approaches using XMLUpdater or XQuery will be discussed in the advanced XML processing tutorials.
 

Tutorials

The following articles and exercises illustrate how to read and write XML data, starting with simple demonstrations and then progressing to more complex workflows.
 

XML Reading

XML Reader Configuration
Converting from XML (Simple XML Reading Example)
 

XML Writing

XML Writing with XMLTemplater
Creating an XML Document in FME with the XMLTemplater Transformer
 

FME Flow

Streaming XML with FME Flow

Was this article helpful?

Comments

1 comment

  • Comment author
    John Perez

    Maybe you should add that in order for FME to read the xml the FME OPTIONS must be first set.  FME OPTIONS/ NETWORK PROXY and be sure that the option “USE SYSTEM PROXY SETTINGS” ist selected.

    0

Please sign in to leave a comment.