Generating FME Schema Features

The XML Reader can switch the given xfMap and XML input document when it is requested for schema features. This can be done through the <schema-type> element’s <generate> element.

The <generate> element contains two required attributes: the xfMap and the document attributes. They specify the xfMap and XML document to used when XML Reader is requested for schema features. In other words, it is possible for the XML Reader to ignore the given xfMap and input XML document by using the <generate> element.

Consider the following input XML document. (It is the same points1.xml document used earlier and reproduced here for convenience.)

points1.xml

<?xml version="1.0" encoding="UTF-8"?>
<points>
	<point name="myPoint" num="0">      
		<color> 
			<red>0.324</red>
			<green>0.233</green>
			<blue>0.596</blue>          
		</color>              
		<location x="10.0" y="0.0"/>    
	</point>   
	<point name="myPoint" num="1">
		<color> 
			<red>0.874</red>
			<green>0.948</green>
			<blue>0.554</blue>          
		</color>              
		<location x="5.0" y="5.0"/>          
	</point>
</points>

The following xfMap document, generate_points1.xmp, maps the elements in the points1.xml document into FME features:

generate_points1.xmp

<?xml version="1.0"?>
<xfMap>	      
	<note>
		This xfMap document maps elements from the points1.xml document.
	</note>

	<schema-type>
		<generate xfMap="generate_points1_schemas.xmp" 			
		document="generate_points1_schemas.xml"/>
	</schema-type>

	<feature-map>      
		<mapping match="point">	   	   	   
			<feature-type> <literal expr="point"/> </feature-type>
			<attributes>
				<attribute>
					<name>  <literal expr="number"/> </name>
					<value> <extract expr="@num"/> </value>
				</attribute>
				<attribute>
					<name>  <literal expr="color"/> </name>
					<value> 
						<extract expr="./color/red"/>	            
						<literal expr=","/>
						<extract expr="./color/green"/>	            
						<literal expr=","/>
						<extract expr="./color/blue"/>	                              
					</value>
				</attribute>	         
			</attributes>	      

			<geometry activate="xml-point">	         	            
				<data name="data-string">	         
					<extract expr="./location[@x]"/>	            
					<literal expr=","/>
					<extract expr="./location[@y]"/>	                           
				</data>
			</geometry>	 
</mapping>	 
</feature-map>					   	
</xfMap>

When the points1.xml and generate_points1.xmp are fed into the XML Reader and FME data features are requested, then the following features are output:

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Feature Type: `point'
Attribute(string): `color' has value `0.324,0.233,0.596'
Attribute(string): `fme_geometry' has value `fme_point'
Attribute(string): `number' has value `0'
Attribute(string): `xml_type' has value `xml_point'
Geometry Type: Point (1)
Number of Coordinates: 1 -- Coordinate Dimension: 2 -- Coordinate System: `'
(10,0) 
==================================================================
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Feature Type: `point'
Attribute(string): `color' has value `0.874,0.948,0.554'
Attribute(string): `fme_geometry' has value `fme_point'
Attribute(string): `number' has value `1'
Attribute(string): `xml_type' has value `xml_point'
Geometry Type: Point (1)
Number of Coordinates: 1 -- Coordinate Dimension: 2 -- Coordinate System: `'
(5,5) 
==================================================================

Notice that the generate_points1.xmp xfMap contains a <schema-type> element. Its child element is the <generate> element whose attributes, xfMap and document attributes, indicate the xfMap (generate_points1_schemas.xmp) and XML document (generate_points1_schemas.xml) to be used when the XML Reader is requested for schema features.

The generate_points1_schemas.xml document contains one <schema-feature> element; this element describes the FME schema feature that we want for the FME data features that are constructed from the points1.xml document through the generate_points1.xmp xfMap.

generate_points1_schemas.xml

<?xml version="1.0" encoding="UTF-8"?>
<schemas>
	<schema-feature type="point">      
		<attribute name="fme_geometry{0}" type="xml_point"/>    
		<attribute name="color" type="xml_char(20)"/>    
		<attribute name="number" type="xml_int16"/>  
		<attribute name="xml_type" type="xml_char(12)"/>                  
	</schema-feature>      
</schemas>

The usage of the <generate> element requires the user to have knowledge of how schema features are represented in FME. Every FME schema feature must have an fme_geometry{} list attribute that lists the possible geometry types of a schema feature. For the XML Reader, the possible values for the fme_geometry{} list attribute are: xml_no_geom, xml_text, xml_point, xml_line, xml_area, and xml_text. If a theme or feature type is capable of containing several geometries (for example, points, lines and areas), then the fme_geometry{} list attribute should contain 3 members:

fme_geometry{0} = “xml_point”
fme_geometry{1} = “xml_line”
fme_geometry{2} = “xml_area”

The type of user attribute, that is, the value of an attribute, must be one of the predefined FME types: xml_char(#), xml_int16, xml_int32, xml_real32, xml_real64, xml_decimal(#,#), or xml_boolean.

The following xfMap generate_points1_schemas.xmp maps the <schema-feature> element into an FME feature.

<?xml version="1.0"?>
<xfMap>	      
	<note>
		This xfMap document maps elements from the 
		generate_points1_schema.xml document.
	</note>
   
	<feature-map>      
		<mapping match="schema-feature">	   	   	   
			<feature-type> <extract expr="@type"/> </feature-type>
		</mapping>	   
	</feature-map>					   	
	
	<feature-content-map>      
		<mapping match="attribute">	   	   	   
			<attributes>
				<attribute type=”sequenced”> 
					<name>  <extract expr="@name"/> </name>
					<value> <extract expr="@type"/> </value>
				</attribute>
			</attributes>
		</mapping>	   
	</feature-content-map>					   	
		
</xfMap>

Note: Nothing dictates that the xfMap generate_points1_schemas.xmp and the generate_points1_schemas.xml document should take the form of the example above. What is required when the <generate> element is used is that an FME feature constructed with the XML document (specified in the document attribute) with the xfMap (specified in the xfMap attribute) by the XML Reader conforms to the definition of an FME schema feature. The FME schema features constructed must contain a fme_geometry{} list attribute, and the attributes defined for the features must have values that equal one of the FME types: xml_char(#), xml_int16, xml_int32, xml_real32, xml_real64, xml_decimal(#,#), or xml_boolean.

The document attribute in the <generate> element may take the special value, #dataset, which instructs the XML Reader to keep given input XML document as the document used for generating the FME schema features.

Example:

<schema-type>
	<generate xfMap=”schemas.xmp” document=”#dataset”/>
</schema-type>

The #self token may be used for the xfMap attribute in the <generate> element. This instructs the XML Reader to use the current xfMap to generate FME schema features. Using #self allows the xfMap to refer to itself without explicitly knowing its filename.

Example:

<schema-type>
 	<generate xfMap=”#self” document=”schemas.xml”/>
 </schema-type>