Background: I don't have much experience with XML. I've got an out of the box application which works with xml schemas and templates. The process is this:
- I should put properly formatted and named xml file in the "Download/Data" folder
- Program detects the file in the "Download/Data" folder, reads it, updates the database using code in xslt files. Xml file is moved into "Download/Processed" folder.
- If the original xml file is not formatted properly, it is moved into "Download/Invalid" folder.
Problem: I need to create xml file that will pass the validation which is properly formatted and will update the database. My current file name is vattaxes.xml and looks like this:
<?xml version="1.0"?>
<VATTax>
<ProcessingDateTime>
</ProcessingDateTime>
<AdditionalInfo>
</AdditionalInfo>
<Header>
<VERSION>5.0.1.7</VERSION>
<StoreId>1</StoreId>
<CreationDate>20140903</CreationDate>
<CreationTime>080636</CreationTime>
<CreatedOn>TPVIRTUAL-PC</CreatedOn>
<Provider>TP.net</Provider>
<Customer>
</Customer>
<Subject>StoreConfigBase</Subject>
<TruncateFields>0</TruncateFields>
</Header>
<createDate>20140903</createDate>
<createTime>082056</createTime>
<actionCode>2</actionCode>
<actionDescription>ADD</actionDescription>
<VATCode>5</VATCode>
<VATLongDescription>20% tax</VATLongDescription>
<VATShortDescription>20% tax</VATShortDescription>
<VATRate>20</VATRate>
<VATStartDate>2014-09-02</VATStartDate>
<VATEndDate>2015-09-03</VATEndDate>
<lastUser>1</lastUser>
</VATTax>
The xsd file that checks whether my file is valid looks like this and is named GV5_VAT.xsd:
<?xml version="1.0"?>
<xsd:schema xmlns="http://www.gold-solutions.com/GoldSchemas"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:gold="http://www.gold-solutions.com/GoldSchemas"
targetNamespace="http://www.gold-solutions.com/GoldSchemas"
elementFormDefault="qualified" attributeFormDefault="unqualified">
<xsd:annotation>
<xsd:documentation xml:lang="en">
G.O.L.D. V5 TVAs schema V1.0
Copyright Aldata 2005
</xsd:documentation>
</xsd:annotation>
<xsd:element name="vattaxes">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="VATTax" type="VATTaxType" minOccurs="0" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute name="processid" type="xsd:integer" use="required"/>
</xsd:complexType>
</xsd:element>
<xsd:complexType name="VATTaxType">
<xsd:sequence>
<xsd:element name="header">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="createDate" type="xsd:date"/>
<xsd:element name="createTime" type="xsd:dateTime"/>
<xsd:element name="actionCode" type ="xsd:integer"/>
<xsd:element name="actionDescription" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:element>
<xsd:element name="VATCode" type="xsd:integer"/>
<xsd:element name="VATLongDescription" type="xsd:string"/>
<xsd:element name="VATShortDescription" type="xsd:string"/>
<xsd:element name="VATSystemCode" type="xsd:integer"/>
<xsd:element name="VATSystemDescription" type="xsd:string"/>
<xsd:element name="VATRate" type="xsd:decimal"/>
<xsd:element name="VATStartDate" type="xsd:date"/>
<xsd:element name="VATEndDate" type="xsd:date"/>
<xsd:element name="lastUser" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
I also have GV5_VAT.xsl
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:gold="http://www.gold-solutions.com/GoldSchemas"
exclude-result-prefixes="gold">
<xsl:output method="xml" indent="yes" encoding="utf-8" />
<!-- Include the header -->
<xsl:include
href="GV5_Base.xsl" />
<!--
Template: match the document (processing starts here)
-->
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<!--
Template: match the root element
-->
<xsl:template name="vattaxes" match="/gold:vattaxes" >
<UpdateDB>
<xsl:call-template name="BuildHeader" />
<xsl:for-each select="./gold:VATTax">
<xsl:call-template name="vattax" />
</xsl:for-each>
</UpdateDB>
</xsl:template>
<!--
Template: match the single nodeRelation element
-->
<xsl:template name="vattax" >
<Transaction>
<!-- Not used elements : -->
<!--
<xsd:element name="VATSystemCode" type="xsd:integer"/>
<xsd:element name="VATSystemDescription" type="xsd:string"/>
<xsd:element name="lastUser" type="xsd:string"/>
-->
<xsl:variable name="szPrintCode" select="./gold:VATShortDescription" />
<xsl:variable name="szExternalID" select="./gold:VATCode" />
<xsl:variable name="szName" select="./gold:VATLongDescription" />
<xsl:variable name="dTaxPercent" select="./gold:VATRate" />
<xsl:variable name="szEffectiveDate" select="concat(concat(substring (./gold:VATStartDate,1,4), substring(./gold:VATStartDate,6,2)), substring(./gold:VATStartDate,9,2))" />
<xsl:variable name="szExpirationDate" select="concat(concat(substring(./gold:VATEndDate,1,4), substring(./gold:VATEndDate,6,2)), substring(./gold:VATEndDate,9,2))" />
<!-- Operation selector -->
<xsl:variable name="actionCode" select="./gold:ACTIONCODE" />
<xsl:choose>
<!-- from here changes for release 3.5 T.S. 05.02.2008 mer-X Software GmbH -->
<!-- Insert -->
<xsl:when test="$actionCode = '2'">
*** sql inserts below***
And the above mentioned GV5_Base.xsl
<?xml version="1.0" ?>
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:gold="http://www.gold-solutions.com/GoldSchemas"
>
<xsl:output method="xml" indent="yes" encoding="utf-8" />
<xsl:variable name="parHeaderCreationDate" />
<xsl:variable name="parHeaderCreationTime" />
<xsl:variable name="parHeaderCreatedOn" />
<xsl:variable name="parHeaderSubject" />
<!--
Template: build header
-->
<xsl:template name="BuildHeader">
<Header>
<Version>3.5.0.0</Version>
<CreationDate><xsl:value-of select="$parHeaderCreationDate"/></CreationDate>
<CreationTime><xsl:value-of select="$parHeaderCreationTime"/></CreationTime>
<CreatedOn><xsl:value-of select="$parHeaderCreatedOn"/></CreatedOn>
<Provider>Aldata Gold</Provider>
<iDocType>positems</iDocType>
<Customer>WN</Customer>
<Subject><xsl:value-of select="$parHeaderSubject"/></Subject>
<TruncateFields>1</TruncateFields>
</Header>
</xsl:template>
</xsl:stylesheet>
The file which is calling them all is fairly straightforward:
<?xml version="1.0" encoding="utf-8" ?>
<PARAMETERS>
<Conversion>
<!--<DownloadFolder>C:\siirto\tuotanto\pos\in</DownloadFolder>-->
<Assembly>not important</Assembly>
<Class>not important</Class>
<Mappings>
<Mapping name="VAT" >
<sourceschema validate="true">GV5_VAT.xsd</sourceschema>
<sourceidentifier>/*[local-name() = 'vattaxes' and namespace-uri() = 'http://www.gold-solutions.com/GoldSchemas']</sourceidentifier>
<xsltfile encoding="UTF-8">GV5_VAT.xsl</xsltfile>
</Mapping>
</Mappings>
</Conversion>
</PARAMETERS>
So, how should I name the .xml file that goes into the Downloads/Data folder and how should it it look inside?