The input text files are converted into XML via the Text to XML module. Below we will illustrate how this module can be activated, and used with the rest of InterFormNG. First consider this input text file:
SETDATA(IDARTNR;123456)
SETDATA(SORTIM;ABC )
SETDATA(BEARTURS;Denmark)
SETDATA(KVQPACK; )
SETDATA(IDBATCH; )
SETDATA(DATECODE;1)
SETDATA(TEETIK-EXT-01;Denmark )
SETDATA(TEETIK-EXT-02;Delicious cookies )
Based on this we would like to set this up in the web interface:
The file extension for this document is .txt, so we add txt and TXT, for the File extensions. Files with any other file extension are ignored by TextToXML.
The Separation regex is a list of the characters, that should be used to separate the values found on each line. We can see, that the characters “;”, “(” and “)” are used for delimiting the data found inside, so we set those as delimiters in the web interface.
Above we tell TextToXML to create a copy of the new xml file to verify how it looks. With the settings above the resulting xml file will be this:
The individual data in the new XML file can be used in a template (inside the designer), but it is not that easy to work with. To retrieve the value of the BEARTURS field we would need this in the Xpath specification:
/root/line[token0002="BEARTURS"]/token0003, which obviously is not a simple click in the XML.
It would be much easier to work with the XML file if e.g. we could have nodes, that are named the same as ‘token0002' with the value found in ‘token0003'. That is possible via a transform, that use this xslt:
<?xml version="1.0" encoding="utf-8" ?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:strip-space elements="*" />
<xsl:output method="xml" standalone="yes" indent="yes" encoding="UTF-8" />
<xsl:template match="line">
<xsl:variable name="t2name"><xsl:value-of select="./token0002" /></xsl:variable>
<xsl:element name="{$t2name}"><xsl:value-of select="./token0003" /></xsl:element>
</xsl:template>
<xsl:template match="node() | @*">
<xsl:copy>
<xsl:apply-templates select="node() | @*" />
</xsl:copy>
</xsl:template>
<xsl:template match="comment()" priority="5"/>
</xsl:stylesheet>
The xslt (transform) removes the leading comment lines and converts the XML structure shown above into this:
Not only is this XML file more simple to look at, but in the designer it also becomes very simple to use, as we can now do a simple click in the XML file to select the node, that we want to output. If we now e.g. want to select the BEARTURS node (which contains Denmark), the simple path is now: /root/BEARTURS.