Introduction
XML is a standard way to exchange data between web services. With FME Server we can easily create a web service to stream almost any kind of geographic information in XML. If you are considering creating an XML Service with FME Server you may also want to have a look at a similar article which deals with streaming GeoJSON with FME Server here:
Streaming GeoJSON with FME Server.
The example below shows how to use FME Workbench to read spatial data and write to XML. We use the XMLTemplater transformer to create the XML document based on a template. The example is published to FME Server and we show the basic syntax for requesting data from this service.
In the second section we will take a quick look at making a similar service with GML data which is an
OGC specification for representing geographic data in XML. Finally there is a brief overview of FME Server's WFS service which is a standard OGC protocol for streaming GML.
View the Ouptput Live:
This example is running live on beta.fmeserver.com. To view the output clicl the link below
Steps for Streaming XML
1. Open the attached workspace template.
2. You will see a bookmark in top left corner where we are adding an attribute for the document root node. This attribute will be converted into an XML element later. For now just be aware that you can create any attributes you want in AttributeCreater transformer and they can be used in the XML document later with XMLTemplater.
3. The bottom left bookmark shows where we read the actual data. In this example we are reading in some sample Bus Route Data in SDF format. An FME Workspace can read any of over 200 hundred formats. You can add your own reader for your own data to this workspace by simply going to the menu Readers -> Add Reader. Be aware that we will be publising the workspace to FME Server so that any file path to data will need to be valid on your FME Server.
4. We can convert the geometry associated with each line into a simple XML structure using the transformer GeometryExtractor with the parameter "FME XML". You could create your own structure for the geometry if you prefer using the XMLTemplater which we will look at in the next step. The output from GeometryExtractor includes an attribute for each bus line called _geometry and inside the attribute will be a valid XML document for each bus line.
The geometries now look like this (there are multiple lines for each bus route hence the <multicurve> element):
<?xml version="1.0" encoding="US_ASCII" standalone="no" ?>
<geometry>
<multicurve><line>
<coord x="3097193.7498751879" y="10035576.9999291"/>
<coord x="3097148.4199133664" y="10035602.950008437"/>
and so on...
3. The XMLTemplater lets us combine all of this information into a single XMLDocument. Open the properties of this transformer in the sample workspace as shown below. In this case we have we are using a ROOT Template and Sub Template for the Bus Routes.
Note: If you have an XML Schema (XSD) file already and need to create a template for the XMLTemplater use the XMLSampleGenerator transformer.

4. First lets look at the ROOT template by clicking on the ellipsis next to the parameter. There only feature entering this template is the feature we created with the Creator and added the CityName attribute to with the AttributeCreator.
<?xml version="1.0" encoding="UTF-8"?>
<CityName>{fme:get-attribute("CityName")}
<BusRoutes>
{fme:process-features("BUSROUTES")}
</BusRoutes></CityName>
The template is first creating a root node element for the CityName. The special place holder function {fme:get-attribute("CityName")} tells FME to take the value from the FME attribute CityName from the feature entering the transformer and insert into the document. You can edit this template to create any elements you want. You can insert values from any attributes as long as they are on the feature entring the ROOT port.
For the BusRoutes element we use the fme:process-features place holder function which tells FME to use values from all of the features using the sub template BUSROUTES (below). Every Bus Route will get inserted as a child of the <BusRoutes> node.
5. Now look at the BUSROUTES Sub Template.
<BusRoute>
<LINE_ID>{fme:get-attribute("LINE_ID")}</LINE_ID>
<LINE_NAME>{fme:get-attribute("LINE_NAME")}</LINE_NAME>
{fme:get-xml-attribute("_geometry")}
</BusRoute>
We want to create child elemements within BusRoute from the Name and ID attributes on the bus routes so we just use the same fme:get-attribute syntax we used above. The _geometry attribute needs to be handled differently. We created the _geometry attribute with GeometryExtractor and each value contains a complete XML document. By using the special funtion in the place holder: fme:get-xml-attribute. the template knows that it will inserting the XML into an existing XML document and it can drop everything but the geometry itself.
6. The output from the XMLTemplater is a single feature with an attribute containing the entire XML document. We can us the XMLFormatter to clean up the line returns etc before writing the data out.
7. The Text Line Writer is used rather than the XML writer beacause at this point we already have the entire XML document in an attribute. We just need to connect the attribute containing the formatted XML data to the text_line_data attribute in the writer. Please note that the writer has a parameter called MIME Type which you can see in the Navigation Pane. We have set this to text/xml so that when we create our web service the proper MIME type is passedin the headers when the data is requested. Save and run the workpsace and examine the XML output file in a text editor.
8. Publish the workspace to any repository you wish on FME Server. Be sure to register the workpace with the Data Streaming Service. If you have used your own data as the source either ensure any file paths are valid on FME Server, or upload the source data with the workspace.
9. Using the FME Server Web User Interface (http://YourHost/fmeserver) we can find the URL that will return the XML data. Login and browse through Data Streaming -> Your Repository -> Your Workspace (XML.fmw). From this configure page click Run and the XML will be returned directly to the browser. FME Server passed the MIME type to browser in the Headers so the browser should be able to display the data as XML.

10. Go back in your browser to the configure page where you ran the workspace from. Notice the Show Request Button. Here we can obtain the URL to access this service from any web application.

In this simple example there are no published parameters in the workspace. If there were parameters you will see the sytax for setting them in the Complete URL text box. In either case, this is the URL to use in your own web application is you want to access the output from an FME Server XML web service.