Entry
Database: SQL: Generate: Structure: Table: XML: How to generate using XML a 'CREATE TABLE': 1?
Jul 6th, 2008 13:27
Knud van Eeden, dman,
----------------------------------------------------------------------
--- Knud van Eeden --- 16 March 2021 - 11:30 pm ----------------------
Database: SQL: Generate: Structure: Table: XML: How to generate using
XML a 'CREATE TABLE': 1?
---
Steps: Overview:
1. -Create an XML file with some data
--- cut here: begin --------------------------------------------------
<!-- -->
<?xml version="1.0" encoding="UTF-8"?>
<!-- -->
<!DOCTYPE MYBOOKS SYSTEM "test.dtd">
<!-- -->
<?xml-stylesheet type="text/xsl" href="test.xsl"?>
<!-- -->
<!-- library: (filenamemacro=test.xml) -->
<!-- -->
<TABLE>
<!-- -->
<TABLENAME>
tableTestS
</TABLENAME>
<!-- -->
<COLUMN>
<!-- -->
<COLUMNNAME>
columnTestKeyPrimaryI
</COLUMNNAME>
<!-- -->
<COLUMNTYPE>
INTEGER
</COLUMNTYPE>
<!-- -->
<COLUMNTYPE>
AUTO_INCREMENT
</COLUMNTYPE>
<!-- -->
<COLUMNTYPE>
NOT NULL
</COLUMNTYPE>
<!-- -->
<COLUMNTYPE>
PRIMARY KEY
</COLUMNTYPE>
<!-- -->
</COLUMN>
<!-- -->
<COLUMN>
<!-- -->
<COLUMNNAME>
columnTestS
</COLUMNNAME>
<!-- -->
<COLUMNTYPE>
VARCHAR( 50 )
</COLUMNTYPE>
<!-- -->
</COLUMN>
<!-- -->
</TABLE>
<!-- -->
--- cut here: end ----------------------------------------------------
2. -Create a DTD file describing the structure
--- cut here: begin --------------------------------------------------
<!-- -->
<!ELEMENT TABLE (TABLENAME, COLUMN+)>
<!-- -->
<!ELEMENT TABLENAME (#PCDATA)>
<!-- -->
<!ELEMENT COLUMN (COLUMNNAME, COLUMNTYPE+)>
<!-- -->
<!ELEMENT COLUMNNAME (#PCDATA)>
<!-- -->
<!ELEMENT COLUMNTYPE (#PCDATA)>
<!-- -->
--- cut here: end ----------------------------------------------------
3. -Create an XSL file describing how it should look like
--- cut here: begin --------------------------------------------------
<!-- -->
<?xml version="1.0"?>
<!-- -->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/TR/WD-xsl">
<!-- -->
<xsl:template match="/">
<xsl:apply-templates/>
</xsl:template>
<!-- -->
<xsl:template match="TABLE">
<HTML>
<HEAD>
<TITLE>
My table
</TITLE>
</HEAD>
<BODY>
<H3> My table </H3>
<BR/>
<BR/>
<HR/>
<xsl:apply-templates/>
<BR/>
)
<BR/>
;
<BR/>
<BR/>
<HR/>
</BODY>
</HTML>
</xsl:template>
<!-- -->
<xsl:template match="TABLENAME">
<FONT SIZE="3" COLOR="blue">
<BR/> CREATE TABLE
<BR/>
<xsl:value-of select="."/>
<xsl:apply-templates/>
</FONT>
<BR/>
(
</xsl:template>
<!-- -->
<xsl:template match="COLUMN">
<BR/>
<xsl:value-of select="."/>
,
</xsl:template>
<!-- -->
<xsl:template match="COLUMNNAME">
<BR/>
<xsl:value-of select="."/>
</xsl:template>
<!-- -->
<xsl:template match="COLUMNTYPE">
<BR/>
<xsl:value-of select="."/>
</xsl:template>
<!-- -->
</xsl:stylesheet>
<!-- -->
--- cut here: end ----------------------------------------------------
4. -Save this XML, DTD and XSL file in the same directory
5. -If you then load the XML file in your browser,
you should see an output similar to the following:
--- cut here: begin --------------------------------------------------
My table
--------------------------------------------------------------------
CREATE TABLE
tableTestS
(
columnTestKeyPrimaryI INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY ,
columnTestS VARCHAR( 50 ) ,
)
;
--------------------------------------------------------------------
--- cut here: end ----------------------------------------------------
---
---
Internet: see also:
---
Database: SQL: Generate: Structure: Link: Can you give overview of
links about generating SQL? [XML]
http://www.faqts.com/knowledge_base/view.phtml/aid/34527/fid/54
----------------------------------------------------------------------