span8
span4
span8
span4
XML is a markup language that enables users to exchange data across web services.In FME Server,a workspace can be published using the Data Streaming Service to easily create a web application to stream spatial data stored as XML.
The example below shows how to create a workspace that takes spatial data and writes it out to XML which can then be published to FME Server to generate a direct URL that can be used to stream the data with in a web service.The second section of this tutorial will provide an overview of the data streaming service with GML format - anOGC specificationfor representing geographic data in XML.
Follow the instructions below to create a workspace that will write out data in XML that can then be published to FME Server using the Data Streaming Service.There is a completed version of this workspace available if you would like to skip to step 8.
An XML document usually comprises of at least two components:
1.Create a City Name attribute
To create the Root element add an AttributeCreator transformer to a blank workspace and set the New Attribute to ‘City Name' and the Attribute Value to ‘Austin Bus Routes'.This transformer requires an input to run so add a Creator transformer before the AttributeCreator.
Attribute Creator parameters dialog box
2.Add an SDF reader
In this example the Sub Template will list the geometry of the bus routes in Austin.First we will need to read in the Transit.sdf dataset.Add a Reader using the following parameters:
Format | Autodesk MapGuide Enterprise SDF |
Dataset |
|
Before selecting OK open up the Parameters...and under Constraints select the ellipsis [...] next to Table List and select the Default.BusRoutes feature.
Add SDF reader and select the Feature Types to read in from Table list
3.Extract feature geometry
Add a GeometryExtractor transformer and connect it to the Reader output port and in the parameters change the Geometry Encoding to ‘FME XML'.This transformer will convert the geometry associated with each bus route into XML structure.
If you were to add an inspector and run the workspace now,each feature would have an additional geometry attribute that will look like this:
....
Notice the
4.Set XML template
Now you have created both of the requirements for the final XML file we can put them together using the XMLTemplater transformer.When this transformer is first added to the canvas it only has a Root input so open the parameter editor and check the Sub Template box and name the port BUSROUTES.
In the Root Template Expression copy the following lines of code:
{fme:get-attribute("CityName")} {fme:process-features("BUSROUTES")}
This template states that the document will be XML and will also write out the value of the CityName attribute created in step 1.
You can edit this template to include additional attribute data as long as the Root port is receiving that data.
Note: Line {fme:process-features("BUSROUTES")} is a placeholder that correlates to the Sub Template we are about to create.Every bus route will be inserted as a child of the
In the Sub Template Expression add the following lines of code:
{fme:get-attribute("LINE_ID")} {fme:get-attribute("LINE_NAME")} {fme:get-xml-attribute("_geometry")}
This sub template is telling the document to add the Bus route ID and Name before detailing the geometry of the route.
Note: Line {fme:get-xml-attribute("_geometry")} pulls in the XML geometry feature created in the GeometryExtractor.Notice here that this is a get-xml-attribute function rather than the usual get-attribute,this is to tell the template that these attributes are already written in XML and to drop everything but the geometry itself.
Note: If you have an XML Schema (XSD) file you can use the XMLSampleGenerator transformer to create an XML Template that can be used as a base in the XMLTemplater.
Before we close the parameter editor change the Result Attribute name to ‘text_line_data'.
5.Connect data to XML Templater
If you have not already done so connect the AttributeCreator to the Root input and the GeometryExtractor to the BUSROUTES input.The XMLTemplater will create a single feature with an attribute containing the entire document.
6.Format the XML file
Add an XMLFormatter and change the Attribute with XML Text to ‘text_line_data' and do the same to the Attribute to contain XML output.We can use this transformer to clean up the lines and appearances before writing the data out.
Set text_line_data attribute to one with XML text
7.Add a Text File Writer
The XML Document is now ready to be exported to a text file.Add a writer with the following parameters:
Format | Text File |
Dataset | Busroutes.xml |
In the Parameters...change the MIME Type to text/xml from the drop-down list.
Add a Text File writer with MIME type set to text/xml
Note: Here we are using the Text File Writer instead of the XML Writer because we have already generated the entire XML Document in a single attribute so all that is needed is to direct the writer to this text_line_data attribute.It is important to set the correct MIME Type when using the data streaming service.
8.Run the Workspace
Before publishing the Workspace to FME Server run the workspace and inspect the output in a text editor to see what you have created.
XML returned to text file
9.Publish the Workspace to FME Server
Publish the workspace to FME Server File > Publish to FME Server.Create a new repository called XML Tutorial and ensure you check the box ‘Upload data files'.Register the workspace to the Data Streaming Service only.
10.Run the workspace using the data streaming service
Open the FME Server Web Interface and find your workspace on the homepage under Last Published Workspaces.Click on the workspace to run it and this will automatically return the XML stream to the browser.Alternatively return to the Run Workspace page and reveal the Advanced section.Here you can find Direct URL to set up a link to run this workspace directly with the web service.
Direct URL example location on FME Server Run Workspace page
Note: You can also create topics to be notified based on the success or failure of this data streaming service.
This example demonstrates how you can write a spatial dataset out to GML format to generate your own XML schema which can be used to stream data in a web service.
1.Generate Workspace with GML reader
Writing to GML is much simpler than writing to XML because it doesn't require any formatting.Open FME Workbench and choose Generate Workspace.Set the parameters using the table below:
Reader Format | Autodesk MapGuide Enterprise SDF |
Reader Dataset |
|
Reader Parameters | Constraints > Table List > Default.BusRoutes |
Writer Format | GML (Geography Markup Language) |
Writer Dataset | C:\Busroutes_GML.gml |
Writer Coordinate System | LL84 |
Generate Workspace complete dialog box
2.Run the workspace
Run the workspace and then hover over the GML Writer and select the Open Containing Folder icon
.Notice that by running this workspace two files were created - the GML file containing all the data and an XML Schema file.
GML and XML Schema file created from running the workspace
3.Update writer to use schema
Return to your workspace and under the Navigator panel right click on the BusRoutes_GML writer and select ‘Update Writer…'.
Update writer in Navigator window
Open the Parameters tab and under GML Version change the settings from 3.1.1 to GML Application Schema and then in the Application Schema browse to the .xsd file that was just created.Once the writer has successfully updated you can now publish the workspace to FME Server.
将XML模式文件添加到GML的作家
4.Publish to FME Server under data streaming service
When publishing the workspace to FME Server register the workspace to the Data Streaming Service and notice this time it is highlighted in red meaning that one or more parameters requires user input for the translation to be a success.Click Edit and click on the ellipse next to ‘Include Browsers to Stream' and make sure the BusRoutes_GML file is selected.
Edit the data streaming service properties to include GML file as writer to stream
5.Run workspace from FME Server
Return to the FME Server Web Interface and select Run Workspace,alternatively the URL to link this data stream to a web service can be found under the Advanced section as in the Streaming XML example.
Snippet of GML stream returned from running the workspace in FME Server
The OGCWeb Feature Service(WFS) is supported by FME Server and has the ability to return features with spatial geometry like the examples covered in this article.Detailed instructions on How to Create a WFS Service Using FME Server can be foundhere.
Alternatively you may be interested in streaming other data formats in which case this article may be of interest:Streaming GeoJSON with FME Server.
Data used in this article originates from open data made available by the theCity of Austin,Texas.It contains data licensed under the Public Domain Dedication License - City of Austin.
Use non-fme namespace prefix with WFS Service (2011/2012 Only)
How to Create a WFS Service Using FME Server
Creating REST Web Services: 4.First an RPC Web Service (2015)
403 Forbidden Error When Making FME Server Request
Creating REST Web Services: 6.Supporting HTTP POST (2015)
Streaming GeoJSON with FME Server (2015)
Creating REST Web Services: 7.Supporting HTTP PUT (2015)
© 2019 亚搏在线Safe Software Inc |Legal