Skip to main content

I'm writing my output to an Excel spreadsheet, but the file also needs to be written to an XML. I've been provided an XSD schema file and using XML Schema Validation in the writer's parameters with the provided file.

I get an error of "no declaration found for element 'xml-tables'. I think I need to declare it in XML Namespace Declarations, but I'm not sure what syntax to use for it. Could you provide any insight, @DeatAtSafe?

Yes, its possible that you are missing a required namespace declaration. However a lot depends on how you created the schema that you are writing to XML. XML is more challenging than GML because you can't just import the schema from an XSD directly onto the writer feature type definition.

There are 2 common approaches to generating this schema. Typically users take an XML element or record from a sample XML dataset and use that as a template within XMLTemplater, replacing values they want to set with fme:get-attribute() functions. Another approach is to use XMLSampleGenerator with the desired destination application schema. This generates sample XML documents based on the selected application schema and element path. If you leave the element path blank it generates a list of possible element names that you can generate. There is an option to generate the namespace header, which you could use to make sure yours is correct. You could also review the elements it constructs as it provides the valid structure including a description of what data types and domain values are allowed for each element.

For example for gmd:individualName below:

 

<gmd:individualName gco:nilReason="">
   <gco:CharacterString><!-- String value. --></gco:CharacterString>
      </gmd:individualName>
      <!-- The gmd:organisationName element is optional. It can occur at most once. -->
      <!-- The gco:nilReason attribute has the following type: An xs:union type. Its value may be any one of the following types: String value. Valid values are: (inapplicable, missing, template, unknown, withheld)

 

We can see that gco:CharacterString takes a String and gco:nilReason takes a value of inapplicable, missing, template, unknown, or withheld. If you use the output of the XMLSampleGenerator to make your XMLTemplate, and follow the element comments closely, then your output should validate against the XSD.

If you get stuck, reply with your workspace, sample input, output and the xml xsd. If you don't want to reply with data to this thread then you can always send it in to  and we can follow up there.

For more on the XMLSampleGenerator see: https://docs.safe.com/fme/html/FME_Desktop_Documentation/FME_Transformers/Transformers/xmlsamplegenerator.htm

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


Thanks for the detailed reply. I was able to begin accomplishing what I'm trying to do using the XMLTemplater transformer. The XSD file was supplied by the customer, so I used that in the Templater and inserted my attributes after generating the template. I then have it going to the AttributeFileWriter as described in this training document: https://cdn.safe.com/training/course-materials/XML-Pathway-Training-Writing-2013.pdf

 

 

Now my issue is that the AttributeFileWriter only writes 1 feature of the 515 that are passed to it. If I'm not on the right path with this writer, I will try the SampleGenerator.

Thanks for the detailed reply. I was able to begin accomplishing what I'm trying to do using the XMLTemplater transformer. The XSD file was supplied by the customer, so I used that in the Templater and inserted my attributes after generating the template. I then have it going to the AttributeFileWriter as described in this training document: https://cdn.safe.com/training/course-materials/XML-Pathway-Training-Writing-2013.pdf

 

 

Now my issue is that the AttributeFileWriter only writes 1 feature of the 515 that are passed to it. If I'm not on the right path with this writer, I will try the SampleGenerator.

As is discussed in the XMLTemplater article I mentioned below under 'Exercise 1.b Basic XML Writing - multi-record': https://knowledge.safe.com/articles/30940/xml-writing-with-xmltemplater.html

The basic idea is that you need to send only one XML document feature per dataset, not 515. So the goal of the XMLTemplater is to produce one document feature from your 515 records. Typically you would have one parent template driven by a Creator and then feed the 515 records into a subtemplate. The example above shows how to do this. I will follow up with you via support email to walk you through how to do this for your case.

 


Reply