Sorting data when writing an XML File
When writing an XML file, data can be sorted with the use of sort keys.
This offers the possibility to order easily the data that is written in the XML file with, if needed, multiple sort keys.
Due to some maintenance operations, stambia.org will be switched to read-only mode during the 13th November. It will be possible to read and download, but impossible to post on the forums or create new accounts. For any question please contact the support team.
When writing an XML file, data can be sorted with the use of sort keys.
This offers the possibility to order easily the data that is written in the XML file with, if needed, multiple sort keys.
When multiple XML files have the same structure, it is possible to process them all at the same time seamlessly.
The XML Metadata and technology in Stambia offers the possibility to use 'Property Fields'.
A Property field is an internal field that can be added to the XML Metadata and that allows to retrieve information such as the file name, path or size at read.
This functionality also permits to define dynamically the XML nodes' name when writing an XML file.
This is particularly useful when the name of the node is containing dynamic data information.
Sometimes, the name of an XML node can contains itself data information.
In this case, the name of the node will vary on each file, on each occurrence or execution.
The Stambia's XML technology offers the possibility to read easily this kind of nodes by specifying a name pattern in the XML Metadata.
It is sometimes useful to generated indented Xml files. This article show an example of how to do this easily, using the "Xslt Transformation" action.
Xml indentation is a visual cumfort when viewing files, but:
- Indentation produces bigger files, which may lead to performance loss
- Some third party applications may behave differently depending on Xml file indentation
- For these reasons, we recommend not to indent files in Production unless it is required
The Xml file is a simple export of customer data, from our demo database.
Here is a sample result:
<?xml version="1.0" encoding="UTF-8"?><customers xmlns:xs="http://www.w3.org/2001/XMLSchema"><person><id>1</id><firstname>Jason</firstname><lastname>GIBBS</lastname><fullname>Jason GIBBS</fullname></person><person><id>2</id><firstname>Michael</firstname><lastname>O'NEAL</lastname><fullname>Michael O'NEAL</fullname></person><person><id>3</id><firstname>Tony</firstname><lastname>JIMENEZ</lastname><fullname>Tony JIMENEZ</fullname></person></customers>
Now let's see how we can indent this.
Xsl transformations can be used to convert Xml files to other Xml structures or to other data formats.
In this example we do not want to alter the Xml structure, so we are going to use an "identity" transformation.
Stambia DI lets you apply Xsl Transformations through the "Xslt Transformation" palette action.
Here is the Xsl Transformation we specified in the action's Expression Editor:
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output omit-xml-declaration="no" indent="yes"/>
<xsl:template match="node()|@*">
<xsl:copy>
<xsl:apply-templates select="node()|@*"/>
</xsl:copy>
</xsl:template>
</xsl:stylesheet>
Our sample result, indented:
<?xml version="1.0" encoding="UTF-8"?>
<customers xmlns:xs="http://www.w3.org/2001/XMLSchema">
<person>
<id>1</id>
<firstname>Jason</firstname>
<lastname>GIBBS</lastname>
<fullname>Jason GIBBS</fullname>
</person>
<person>
<id>2</id>
<firstname>Michael</firstname>
<lastname>O'NEAL</lastname>
<fullname>Michael O'NEAL</fullname>
</person>
<person>
<id>3</id>
<firstname>Tony</firstname>
<lastname>JIMENEZ</lastname>
<fullname>Tony JIMENEZ</fullname>
</person>
</customers>