Page 1 of 1

Relational Schema XML to SQL

Posted: Wed Mar 18, 2009 1:23 am
by djharris
Has anyone run across a "generic" transform, or the beginnings of one, that can take an xml with a fairly complex schema and extract it into multiple "single-table" XML files? My ultimate target is to import the data into a legacy cobol system and I'm wondering just how far I can take things using just XSLT.

The schema I'm looking at is built completely on itself with complexTypes and simpleTypes that are defined within the schema itself. I'd like to extract the complex types data into separate tables with relational keys between them. I have been able to do this with hard-coded transforms but I'd like to build an auto-discovery transform that takes what it can from the schema to determine how to split the xml.

This seems, to me, like it might be a common need, so I'm wondering if anyone has seen or done this? I have the XSLT Cookbook but haven't really found a solution for this complex of a problem.

I've posted a similar schema before but here it is again (obfuscated but valid as I don't have permission to post it):

Code: Select all

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<xs:schema xmlns:sdr="https://www.Cc.org/XXX.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="https://www.Cc.org/XXX.xsd"
elementFormDefault="qualified" attributeFormDefault="unqualified" id="XXX">
<xs:annotation>
<xs:documentation xml:lang="en">XXX Schema Bx Bz . All rights
reserved.</xs:documentation>
</xs:annotation>
<xs:annotation>
<xs:documentation xml:lang="en">XXX Schema V Cb Bx Ca . All rights
reserved.</xs:documentation>
</xs:annotation>
<xs:element name="XXXAa" type="sdr:XXXAaType"/>
<xs:element name="XXX">
<xs:complexType>
<xs:all>
<xs:element ref="sdr:XXXAa"/>
</xs:all>
<xs:attribute name="XXXAbAc" type="sdr:XXXAbType" use="optional"/>
<xs:attribute name="SchemaAd" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>
<xs:simpleType name="XXXAbType">
<xs:restriction base="xs:base64Binary">
<xs:maxLength value="10000"/>
</xs:restriction>
</xs:simpleType>
<xs:complexType name="XXXAaType">
<xs:all>
<xs:element name="AeAfAg" type="sdr:AfAgType" minOccurs="0"/>
<xs:element name="AeAh" type="xs:string" minOccurs="0"/>
<xs:element name="AiByAeAj" type="xs:string" minOccurs="0"/>
<xs:element name="XXXAkName" type="xs:string" minOccurs="0"/>
<!--
add more XXX header info HERE
xml file version maybe
etc...
-->
</xs:all>
</xs:complexType>
<xs:complexType name="AlAmType">
<xs:all>
<xs:element name="An" type="sdr:BsBr50CharType" minOccurs="0"/>
<xs:element name="AmAo1">
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="sdr:BuBvType"/>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="AmAo2" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="AmAo3" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="City">
<xs:simpleType>
<xs:union>
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType>
<xs:restriction base="sdr:BuBvType"/>
</xs:simpleType>
</xs:union>
</xs:simpleType>
</xs:element>
<xs:element name="ApOrState" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="AqAr" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="As" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>
<xs:complexType name="AmType">
<xs:all>
<xs:element name="An" type="sdr:BsBr50CharType" minOccurs="0"/>
<xs:element name="AtAu" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="sdr:BsBr10CharType sdr:BuBvType"/>
</xs:simpleType>
</xs:element>
<xs:element name="AtAv" type="sdr:BsBr3CharType" minOccurs="0"/>
<xs:element name="AtAw" type="sdr:AtAwType" minOccurs="0"/>
<xs:element name="AtName" minOccurs="0">
<xs:simpleType>
<xs:union memberTypes="sdr:BsBr50CharType sdr:BuBvType"/>
</xs:simpleType>
</xs:element>
<xs:element name="AtAx" type="sdr:BbAtAxType" minOccurs="0"/>
<xs:element name="AyType" type="sdr:BbAyBwType" minOccurs="0"/>
<xs:element name="AyAu" type="sdr:BsBr10CharType" minOccurs="0"/>
<xs:element name="AzBa" type="sdr:BsBr10CharType" minOccurs="0"/>
<xs:element name="City">
<xs:simpleType>
<xs:union memberTypes="sdr:BsBr25CharType sdr:BuBvType"/>
</xs:simpleType>
</xs:element>
<xs:element name="State">
<xs:simpleType>
<xs:union memberTypes="sdr:StateType sdr:BuBvType"/>
</xs:simpleType>
</xs:element>
<xs:element name="BcAr">
<xs:simpleType>
<xs:union memberTypes="sdr:BuBvType sdr:BcArType"/>
</xs:simpleType>
</xs:element>
</xs:all>
</xs:complexType>
<xs:complexType name="AfAgType">
<xs:all>
<xs:element name="NameBd" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="Mr.|Mrs.|Ms.|Sir"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="BeName">
<xs:simpleType>
<xs:union memberTypes="sdr:BsBr50CharType sdr:BuBvType"/>
</xs:simpleType>
</xs:element>
<xs:element name="BfName" type="sdr:BsBr50CharType" minOccurs="0"/>
<xs:element name="BgName" type="sdr:BsBr25CharType" minOccurs="0"/>
<xs:element name="BhName" type="sdr:BsBr25CharType" minOccurs="0"/>
<xs:element name="Bi" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:maxLength value="1"/>
<xs:pattern value="[a-zA-Z]"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="NameBl" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:pattern value="Jr.|Sr."/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Bm" type="sdr:BsBr50CharType" minOccurs="0"/>
<xs:element name="Bn">
<xs:simpleType>
<xs:union memberTypes="sdr:BuBvType sdr:BtAuType"/>
</xs:simpleType>
</xs:element>
<xs:element name="BnBo" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:integer">
<xs:minInclusive value="0"/>
<xs:maxInclusive value="99999"/>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="Bp" type="sdr:BtAuType" minOccurs="0"/>
<xs:element name="Bq" type="sdr:BqType" minOccurs="0"/>
</xs:all>
</xs:complexType>
<xs:simpleType name="StateType">
<xs:restriction base="xs:string">
<xs:pattern
value="(A[LKSZRAP]|C[AOT]|D[EC]|F[LM]|G[AU]|HI|I[ADLN]|K[SY]|LA|M[ADEHINOPST]|N[CDEHJMVY]|O[HKR]|P[ARW]|RI|S[CD]|T[NX]|UT|V[AIT]|W[AIVY])"
/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="BcArType">
<xs:restriction base="xs:string">
<xs:pattern value="\d{5}(-\d{4})?"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="XXXStringType">
<xs:restriction base="xs:string">
<xs:pattern value="[a-zA-Z0-9\s.\-/_'(),{}@$!#&%]+"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="BsBr3CharType">
<xs:restriction base="sdr:XXXStringType">
<xs:maxLength value="3"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="BsBr10CharType">
<xs:restriction base="sdr:XXXStringType">
<xs:maxLength value="10"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="BsBr25CharType">
<xs:restriction base="sdr:XXXStringType">
<xs:maxLength value="25"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="BsBr50CharType">
<xs:restriction base="sdr:XXXStringType">
<xs:maxLength value="50"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="AtAwType">
<xs:restriction base="xs:string">
<xs:pattern value="n|N|s|S|w|W|e|E|ne|Ne|nE|NE|nw|Nw|nW|NW|se|Se|sE|SE|sw|Sw|sW|SW"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="BtAuType">
<xs:restriction base="xs:string">
<xs:pattern value="\(?[1-9][0-9][0-9]\)?-?[1-9][0-9][0-9]-?[0-9][0-9][0-9][0-9]"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="BqType">
<xs:restriction base="xs:string">
<xs:pattern
value="([0-9a-zA-Z]([-.\w]*[0-9a-zA-Z])*@(([0-9a-zA-Z])+([-\w]*[0-9a-zA-Z])*\.)+[a-zA-Z]{2,9})"
/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="BuBvType">
<xs:restriction base="xs:string">
<xs:pattern value="N/A|n/a"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="BbAyBwType">
<xs:restriction base="xs:string">
<xs:enumeration value="APT"/>
<xs:enumeration value="BSMT"/>
<xs:enumeration value="BLDG"/>
</xs:restriction>
</xs:simpleType>
<xs:simpleType name="BbAtAxType">
<xs:restriction base="xs:string">
<xs:enumeration value="ALY"/>
<xs:enumeration value="ANX"/>
<xs:enumeration value="ARC"/>
</xs:restriction>
</xs:simpleType>
</xs:schema>