How to create a database from an XML file's DTD I have a fairly large and complex self-describing XML file (It's an Apple Healthkit export; 183 MB).   

Are there any utilities available to create a database in MySQL or PostgreSQL  with the tables and fields described in the XML file's DTD?  

(If not, I suppose PHP's SimpleXML Parser would help but would require more thought.)

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE HealthData [
&lt;!-- HealthKit Export Version: 3 --&gt;
&lt;!ELEMENT HealthData (ExportDate,Me,(Record|Correlation|Workout|ActivitySummary)*)&gt;
&lt;!ATTLIST HealthData
  locale CDATA #REQUIRED
&gt;
&lt;!ELEMENT ExportDate EMPTY&gt;
&lt;!ATTLIST ExportDate
  value CDATA #REQUIRED
&gt;
&lt;!ELEMENT Me EMPTY&gt;
&lt;!ATTLIST Me
  HKCharacteristicTypeIdentifierDateOfBirth         CDATA #REQUIRED
  HKCharacteristicTypeIdentifierBiologicalSex       CDATA #REQUIRED
  HKCharacteristicTypeIdentifierBloodType           CDATA #REQUIRED
  HKCharacteristicTypeIdentifierFitzpatrickSkinType CDATA #REQUIRED
&gt;
&lt;!ELEMENT Record (MetadataEntry*)&gt;
&lt;!ATTLIST Record
  type          CDATA #REQUIRED
  unit          CDATA #IMPLIED
  value         CDATA #IMPLIED
  sourceName    CDATA #REQUIRED
  sourceVersion CDATA #IMPLIED
  device        CDATA #IMPLIED
  creationDate  CDATA #IMPLIED
  startDate     CDATA #REQUIRED
  endDate       CDATA #REQUIRED
&gt;
&lt;!-- Note: Any Records that appear as children of a correlation also appear as top-level records in this document. --&gt;
&lt;!ELEMENT Correlation ((MetadataEntry|Record)*)&gt;
&lt;!ATTLIST Correlation
  type          CDATA #REQUIRED
  sourceName    CDATA #REQUIRED
  sourceVersion CDATA #IMPLIED
  device        CDATA #IMPLIED
  creationDate  CDATA #IMPLIED
  startDate     CDATA #REQUIRED
  endDate       CDATA #REQUIRED
&gt;
&lt;!ELEMENT Workout ((MetadataEntry|WorkoutEvent)*)&gt;
&lt;!ATTLIST Workout
  workoutActivityType   CDATA #REQUIRED
  duration              CDATA #IMPLIED
  durationUnit          CDATA #IMPLIED
  totalDistance         CDATA #IMPLIED
  totalDistanceUnit     CDATA #IMPLIED
  totalEnergyBurned     CDATA #IMPLIED
  totalEnergyBurnedUnit CDATA #IMPLIED
  sourceName            CDATA #REQUIRED
  sourceVersion         CDATA #IMPLIED
  device                CDATA #IMPLIED
  creationDate          CDATA #IMPLIED
  startDate             CDATA #REQUIRED
  endDate               CDATA #REQUIRED
&gt;
&lt;!ELEMENT WorkoutEvent EMPTY&gt;
&lt;!ATTLIST WorkoutEvent
  type CDATA #REQUIRED
  date CDATA #REQUIRED
&gt;
&lt;!ELEMENT ActivitySummary EMPTY&gt;
&lt;!ATTLIST ActivitySummary
  dateComponents           CDATA #IMPLIED
  activeEnergyBurned       CDATA #IMPLIED
  activeEnergyBurnedGoal   CDATA #IMPLIED
  activeEnergyBurnedUnit   CDATA #IMPLIED
  appleExerciseTime        CDATA #IMPLIED
  appleExerciseTimeGoal    CDATA #IMPLIED
  appleStandHours          CDATA #IMPLIED
  appleStandHoursGoal      CDATA #IMPLIED
&gt;
&lt;!ELEMENT MetadataEntry EMPTY&gt;
&lt;!ATTLIST MetadataEntry
  key   CDATA #REQUIRED
  value CDATA #REQUIRED
&gt;
]&gt;
&lt;HealthData locale="en_GB"&gt; ... etc. (data)
Use the following tools:


  1) create full sql schema from DTD.



DTDParse + XML::RDB



  2) convert XML doc with data into SQL.



https://stackoverflow.com/questions/13121456/transform-xml-using-xslt-to-sql


References


DTD Tools (the link no longer works)
XML Matters: Using Python modules xml2sql and dtd2sql