Creating a File _ Database Import - Eonic/ProteanCMS GitHub Wiki
Make sure that you have the latest version of ProteanCMS.
We can create a bespoke import of a range of different filetypes and database connections.
We can import from xlsx and xls files they get converted to XML and then XSLT is passed against them.
We can import directly from an xml file
We can import from an XML file that specifies a database connection and a table or view to convert to XML.
Make sure that you have the latest version of the mySQL ProteanCMS provider.
Within the xsl file located in the root of the project create the folder import
.
Add an xsl file in the newly created import folder with a suitable name. For example, [bulkImportName].xsl
.
That XSL file will convert the incoming XML format to the XML required for Import Objects which is a series of "xml instances" of the items needed to be saved or updated.
To start the newly created file let's add the following code to file.
<xsl:template match="/Bible">
<Instances>
<DeleteNonEntries enabled="false">
<cDefiningField>cContentForiegnRef</cDefiningField>
</DeleteNonEntries>
<SkipExisting enabled="false"/>
<NoLocations enabled="false"/>
<ResetLocations enabled="true"/>
<xsl:for-each select="Book">
<instance update="relocate">
<tblContent>
<nContentKey/>
<nContentPrimaryId/>
<nVersion/>
<cContentForiegnRef\>
<cContentName\>
<cContentSchemaName>[ContentTypeName]</cContentSchemaName>
<cContentXmlBrief>
<Content>
<!-- Content Brief information goes here -->
</Content>
</cContentXmlBrief>
<cContentXmlDetail>
<Content>
<!-- Content Detail information goes here -->
</Content>
</cContentXmlDetail>
<nAuditId/>
<nAuditKey/>
<dPublishDate/>
<StartDate/>
<dExpireDate/>
<dInsertDate/>
<nInsertDirId/>
<dUpdateDate/>
<nUpdateDirId/>
<nStatus>1</nStatus>
<cDescription/>
</tblContent>
<[Relation or Location]>
</instance>
</xsl:for-each>
</Instances>
</xsl:template>
Some of the most importance items to highlight in this example would be the <cContentSchemaName>
, this tag will need to hold the name of the ContentType that you're going to be importing the data into.
The content in both the <cContentXmlBrief>
and <cContentXmlDetail>
will also need to use the same content that is already being used in your ContentType. For example, if the ContentType includes a <Name>
in the <cContentXmlBrief>
and a <Name>
and <Body>
in the <cContentXmlDetail>
that will also need to be reflected in the import.xsl as shown in the following example.
<cContentXmlBrief>
<Content>
<Name>
<xsl:value-of select="Name"/>
</Name>
</Content>
</cContentXmlBrief>
<cContentXmlDetail>
<Content>
<Name>
<xsl:value-of select="Name"/>
</Name>
<Body>
<xsl:copy-of select="Body"/>
</Body>
</Content>
</cContentXmlDetail>
You're also going to want to create a new XML file named ImportManifest.xml
within the import folder.
Let's add the following code to the newly created ImportMainfest.xml
to start it off.
<?xml version="1.0" encoding="utf-8"?>
<Imports>
<ImportGroup name="Imports">
<Import name="[BulkImportName]" xslFile="[bulkImportName].xsl" importDoc="XML">[BulkImportName]</Import>
</ImportGroup>
</Imports>
Next you're going to want to create a new
You're going to want to want to replace the [BulkImportName]
fields with suitable names that relate to the type of bulk import that you're doing.
Now you're bulk import should be visible within ProteanCMS going to Settings/Import Files
Firstly to a trial import without saving to view the XML of the file you are importing.
Then modify the XSLT to create the instances and test again until you are happy.
ALWAYS specify a Foreign reference for imports so you can update them later if you need to make changes.
Finally, add a reference to the new mySQL database provider to the website.
Add the mySQL provider to the project in visual studio.
Within web.config add the database provider like the example as shown below.
<protean>
<databaseProviders>
<providers>
<add name="MySQL" type="Protean.Providers.Database.MySQL, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</providers>
</databaseProviders>
<protean/>