SetFile
Last modified by Outhman Moustaghfir on 2024/11/28 14:50
Purpose:
The SetFile method is designed to store XML content in a database by saving it as a file and returning the file's unique identifier.
How it Works:
- The method takes XML content as input.
- It writes the XML content to a file.
- The file is saved in the database, and its file ID is returned for future reference.
optional parameters:
- fileName (optional): Specifies a custom name for the saved file. If not provided (null or empty), the file will be saved with its unique file ID as the name.
- folder (optional): Defines the folder where the file will be stored (e.g., "work", "out", etc.). If not specified (null or empty), the file will be placed in the default "work" folder.
- synchrone (optional): Defaults to false. Determines whether the file is set synchronously or asynchronously
SetFile(xmlContent,fileName,folder)
Usage Example:
Consider the following XSLT transformation that calls the SetFile method:
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:ixf="http://www.ixPath.com/Function"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ix="localFunction"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
version="2.0">
<xsl:output method="xml" indent="yes"></xsl:output>
<!-- Start of the Transformation -->
<xsl:template match="/">
<iXDOC>
<!-- Define the XML content you want to save -->
<xsl:variable name="xmlContent">
<MyXML>
<XML>
<iXDoc>
<Invoice>
<InvoiceHeader>
<InvoiceNumber>123456</InvoiceNumber>
<InvoiceDate>2019-01-01</InvoiceDate>
<InvoiceDueDate>2019-01-31</InvoiceDueDate>
<InvoiceCurrency>USD</InvoiceCurrency>
<InvoiceTotal>1000.00</InvoiceTotal>
<InvoiceTax>100.00</InvoiceTax>
<InvoiceNet>900.00</InvoiceNet>
<InvoicePaid>0.00</InvoicePaid>
<InvoiceBalance>900.00</InvoiceBalance>
<InvoiceStatus>Open</InvoiceStatus>
<InvoiceTerms>Net 30</InvoiceTerms>
<InvoiceNotes>Thank you for your business!</InvoiceNotes>
</InvoiceHeader>
<!-- Additional Invoice Items -->
</Invoice>
</iXDoc>
</XML>
</MyXML>
</xsl:variable>
<!-- Call the SetFile method and pass the XML content -->
<xsl:variable name="fileId" select="ixf:SetFile($xmlContent)"></xsl:variable>
<!-- Output the ID of the saved file -->
<returnedFiles>
<fileId>
<xsl:value-of select="$fileId"></xsl:value-of>
</fileId>
</returnedFiles>
</iXDOC>
</xsl:template>
</xsl:stylesheet>
xmlns:ixf="http://www.ixPath.com/Function"
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:ix="localFunction"
xmlns:fn="http://www.w3.org/2005/xpath-functions"
version="2.0">
<xsl:output method="xml" indent="yes"></xsl:output>
<!-- Start of the Transformation -->
<xsl:template match="/">
<iXDOC>
<!-- Define the XML content you want to save -->
<xsl:variable name="xmlContent">
<MyXML>
<XML>
<iXDoc>
<Invoice>
<InvoiceHeader>
<InvoiceNumber>123456</InvoiceNumber>
<InvoiceDate>2019-01-01</InvoiceDate>
<InvoiceDueDate>2019-01-31</InvoiceDueDate>
<InvoiceCurrency>USD</InvoiceCurrency>
<InvoiceTotal>1000.00</InvoiceTotal>
<InvoiceTax>100.00</InvoiceTax>
<InvoiceNet>900.00</InvoiceNet>
<InvoicePaid>0.00</InvoicePaid>
<InvoiceBalance>900.00</InvoiceBalance>
<InvoiceStatus>Open</InvoiceStatus>
<InvoiceTerms>Net 30</InvoiceTerms>
<InvoiceNotes>Thank you for your business!</InvoiceNotes>
</InvoiceHeader>
<!-- Additional Invoice Items -->
</Invoice>
</iXDoc>
</XML>
</MyXML>
</xsl:variable>
<!-- Call the SetFile method and pass the XML content -->
<xsl:variable name="fileId" select="ixf:SetFile($xmlContent)"></xsl:variable>
<!-- Output the ID of the saved file -->
<returnedFiles>
<fileId>
<xsl:value-of select="$fileId"></xsl:value-of>
</fileId>
</returnedFiles>
</iXDOC>
</xsl:template>
</xsl:stylesheet>
Output:
The method will return the unique ID of the file saved in the database, which can be accessed as shown in the XSLT example.