faqts : Computers : Databases

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

1 of 2 people (50%) answered Yes
Recently 1 of 2 people (50%) answered Yes

Entry

Database: SQL: Generate: Structure: Table: XML: How to generate using XML a 'CREATE TABLE': 2?

Jul 6th, 2008 13:27
Knud van Eeden, dman,


----------------------------------------------------------------------
--- Knud van Eeden --- 16 March 2005 - 11:50 pm ----------------------
Database: SQL: Generate: Structure: Table: XML: How to generate using 
XML a 'CREATE TABLE': 2?
---
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)  -->
<!--                                                                -->
<TABLES>
<!--                                                                -->
<TABLE>
<!--                                                                -->
<TABLENAME>
  tableTest1S
</TABLENAME>
<!--                                                                -->
<COLUMN>
<!--                                                                -->
<COLUMNNAME>
  columnTest1KeyPrimaryI
</COLUMNNAME>
<!--                                                                -->
<COLUMNTYPE>
  INTEGER
</COLUMNTYPE>
<!--                                                                -->
<COLUMNTYPE>
  AUTO_INCREMENT
</COLUMNTYPE>
<!--                                                                -->
<COLUMNTYPE>
  NOT NULL
</COLUMNTYPE>
<!--                                                                -->
<COLUMNTYPE>
  PRIMARY KEY
</COLUMNTYPE>
<!--                                                                -->
</COLUMN>
<!--                                                                -->
<COLUMN>
<!--                                                                -->
<COLUMNNAME>
  columnTest1S
</COLUMNNAME>
<!--                                                                -->
<COLUMNTYPE>
  VARCHAR( 50 )
</COLUMNTYPE>
<!--                                                                -->
</COLUMN>
<!--                                                                -->
</TABLE>
<!--                                                                -->
<TABLE>
<!--                                                                -->
<TABLENAME>
  tableTest2S
</TABLENAME>
<!--                                                                -->
<COLUMN>
<!--                                                                -->
<COLUMNNAME>
  columnTest2KeyPrimaryI
</COLUMNNAME>
<!--                                                                -->
<COLUMNTYPE>
  INTEGER
</COLUMNTYPE>
<!--                                                                -->
<COLUMNTYPE>
  AUTO_INCREMENT
</COLUMNTYPE>
<!--                                                                -->
<COLUMNTYPE>
  NOT NULL
</COLUMNTYPE>
<!--                                                                -->
<COLUMNTYPE>
  PRIMARY KEY
</COLUMNTYPE>
<!--                                                                -->
</COLUMN>
<!--                                                                -->
<COLUMN>
<!--                                                                -->
<COLUMNNAME>
  columnTest2S
</COLUMNNAME>
<!--                                                                -->
<COLUMNTYPE>
  VARCHAR( 50 )
</COLUMNTYPE>
<!--                                                                -->
</COLUMN>
<!--                                                                -->
</TABLE>
<!--                                                                -->
</TABLES>
<!--                                                                -->
--- cut here: end ----------------------------------------------------
 2. -Create a DTD file describing the structure
--- cut here: begin --------------------------------------------------
<!--                                                                -->
 <!ELEMENT TABLES (TABLE+)>
<!--                                                                -->
 <!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="TABLES">
   <HTML>
    <HEAD>
     <TITLE>
       My table
     </TITLE>
    </HEAD>
    <BODY>
     <H3> My table </H3>
     <BR/>
     <BR/>
     <HR/>
      <xsl:apply-templates/>
     <BR/>
     <BR/>
     <HR/>
    </BODY>
   </HTML>
 </xsl:template>
<!--                                                                -->
 <xsl:template match="TABLE">
   <BR/>
    <xsl:apply-templates/>
  <BR/>
  )
  <BR/>
  ;
 </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
tableTest1S
(
columnTest1KeyPrimaryI INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY ,
columnTest1S VARCHAR( 50 ) ,
)
;
CREATE TABLE
tableTest2S
(
columnTest2KeyPrimaryI INTEGER AUTO_INCREMENT NOT NULL PRIMARY KEY ,
columnTest2S 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
----------------------------------------------------------------------