Question

SUB template parsing error in XMLtemplater


Hello,

I am trying to create a GML with XML templater.

My reader is Shapefile format.

0684Q00000ArEDkQAN.png

When I paste the sub-element template in the root template I don't have any errors (but then of course the file isn't valid).

However, I have the following error when I try to add a sub-element:

XMLTemplater(XMLTemplaterFactory): The following error occurred near line 19, column 6 of the query: 
XMLTemplater(XMLTemplaterFactory): "gml": can not expand namespace prefix to URI 
XMLTemplater(XMLTemplaterFactory): An error occurred while parsing the 'SUB' sub-template 
XMLTemplater(XMLTemplaterFactory): A fatal error has occurred. Check the logfile above for details A fatal error has occurred. Check the logfile above for details

 

XML templater:

0684Q00000ArEDpQAN.png

With the following for the SUB template:

<?xml version="1.0" encoding="UTF-8"?>
<gml:FeatureCollection xmlns:za="http://osi.irisnetlab.be/gml" xmlns:gml="http://www.opengis.net/gml">    
<za:LayerNameFr>$(Layer_Name_FR)</za:LayerNameFr>    
<za:LayerNameNl>$(Layer_Name_NL)</za:LayerNameNl>    
{fme:process-features("SUB")}
</gml:FeatureCollection>

And for the SUB template:

<gml:featureMember>
        <za:NameFr>Cluster n°{fme:get-attribute("NBCLUS")} - Responsable: {fme:get-attribute("resp")}</za:NameFr>
        <za:From>15/06/2019</za:From>
        <za:To>15/12/2019</za:To>
        <za:Comment>{fme:get-attribute("A_list_ws")}</za:Comment>
        <za:TypeZa>Autre</za:TypeZa>
        <gml:surfaceProperty>
          <gml:Surface srsName="EPSG:31370" srsDimension="2">
            <gml:patches>
              <gml:PolygonPatch>
                <gml:exterior>
                  <gml:LinearRing>
                    <gml:posList>{geom:get-points()}</gml:posList>
                  </gml:LinearRing>
                </gml:exterior>
              </gml:PolygonPatch>
            </gml:patches>
          </gml:Surface>
        </gml:surfaceProperty>
 </gml:featureMember>

Could someone hint me in the right direction?

Thank you !


2 replies

Badge +6

All templates - both ROOT and any SUBs - need to be a valid XML document. That means if you have any elements with a namespace prefix, you need to include a namespace definition in the header for the template. So for your sub, you need to include xmlns:gml and xmlns:za in your top level element tag such as:

<gml:featureMember xmlns:za="http://osi.irisnetlab.be/gml" xmlns:gml="http://www.opengis.net/gml">...

Yes, this will result in redundant namespace declarations in your templater's combined xml output. But that's no problem since it's still valid, and you can always clean them up with the XMLFormatter afterwards.

Note that every input feature to ROOT will generate a separate XML document, so if you expect to have many instances of SUB within ROOT make sure you feed the XMLTemplater correctly.

My question would be why are you using XMLTemplater to write GML? This used to be the only way to write GML for custom application schemas, but now that we have an application schema based GML writer, you can just import the feature type definitions from any app schema and write to GML just like you would any other format. 

For more on this see: https://knowledge.safe.com/articles/812/gml-writing-with-application-schemas.html 

Also, the INSPIRE tutorial has many good examples of how to write GML: https://knowledge.safe.com/articles/1321/eu-inspire-initiative-tutorial.html 

For more on XMLTemplater see: https://knowledge.safe.com/articles/30940/xml-writing-with-xmltemplater.html 

 

All templates - both ROOT and any SUBs - need to be a valid XML document. That means if you have any elements with a namespace prefix, you need to include a namespace definition in the header for the template. So for your sub, you need to include xmlns:gml and xmlns:za in your top level element tag such as:

<gml:featureMember xmlns:za="http://osi.irisnetlab.be/gml" xmlns:gml="http://www.opengis.net/gml">...

Yes, this will result in redundant namespace declarations in your templater's combined xml output. But that's no problem since it's still valid, and you can always clean them up with the XMLFormatter afterwards.

Note that every input feature to ROOT will generate a separate XML document, so if you expect to have many instances of SUB within ROOT make sure you feed the XMLTemplater correctly.

My question would be why are you using XMLTemplater to write GML? This used to be the only way to write GML for custom application schemas, but now that we have an application schema based GML writer, you can just import the feature type definitions from any app schema and write to GML just like you would any other format. 

For more on this see: https://knowledge.safe.com/articles/812/gml-writing-with-application-schemas.html 

Also, the INSPIRE tutorial has many good examples of how to write GML: https://knowledge.safe.com/articles/1321/eu-inspire-initiative-tutorial.html 

For more on XMLTemplater see: https://knowledge.safe.com/articles/30940/xml-writing-with-xmltemplater.html 

 

Thank you, problem solved :) 

 

Using Templater because I am not comfortable with the GML writer.

Reply