title: Importing an xml schema into postgres to automatically create a table and then populate it with an xml file?
body: <p>I have a huge xml file that I cannot open unless I import it into a database. I am using Postgres for this. I have a schema that goes with this data file. There are too many columns so i'd like to automate the process of creating a table from this schema and then importing the data file from the local drive on my computer to populate this table. How do i do this?
  I saw a lot of answers on SO but haven't been able to understand this correctly. Also I do not have superuser rights so will have to work around that. </p>
  
  <p>Here's what the schema file looks like:</p>
  
  <pre><code>&gt; &lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;xs:schema
  &gt; xmlns:xs="http://www.w3.org/2001/XMLSchema"
  &gt; elementFormDefault="qualified"
  &gt;     targetNamespace="http://www.drugbank.ca" xmlns="http://www.drugbank.ca"&gt;
  &gt;     &lt;xs:element name="drugbank" type="drugbank-type"&gt;
  &gt;         &lt;xs:annotation&gt;
  &gt;             &lt;xs:documentation&gt;This is the root element for the DrugBank database schema. DrugBank is a database on drug and
  &gt; drug-targets.&lt;/xs:documentation&gt;
  &gt;         &lt;/xs:annotation&gt;
  &gt;     &lt;/xs:element&gt;
  &gt;     &lt;xs:complexType name="drugbank-type"&gt;
  &gt;         &lt;xs:annotation&gt;
  &gt;             &lt;xs:documentation&gt;This is the root element type for the DrugBank database schema.&lt;/xs:documentation&gt;
  &gt;         &lt;/xs:annotation&gt;
  &gt;         &lt;xs:sequence&gt;
  &gt;             &lt;xs:element name="drug" type="drug-type" maxOccurs="unbounded"/&gt;
  &gt;         &lt;/xs:sequence&gt;
  &gt;         &lt;xs:attribute name="version" type="xs:string" use="required"&gt;
  &gt;             &lt;xs:annotation&gt;
  &gt;                 &lt;xs:documentation&gt;The DrugBank version for the exported XML file.&lt;/xs:documentation&gt;
  &gt;             &lt;/xs:annotation&gt;
  &gt;         &lt;/xs:attribute&gt;
  &gt;         &lt;xs:attribute name="exported-on" type="xs:date" use="required"&gt;
  &gt;             &lt;xs:annotation&gt;
  &gt;                 &lt;xs:documentation&gt;The date the XML file was exported.&lt;/xs:documentation&gt;
  &gt;             &lt;/xs:annotation&gt;
  &gt;         &lt;/xs:attribute&gt;
  &gt;     &lt;/xs:complexType&gt;
  &gt;     &lt;xs:complexType name="drug-type"&gt;
  &gt;         &lt;xs:sequence&gt;
  &gt;             &lt;xs:element maxOccurs="unbounded" minOccurs="1" name="drugbank-id"
  &gt;                 type="drugbank-drug-salt-id-type"&gt; &lt;/xs:element&gt;
  &gt;             &lt;xs:element name="name" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="description" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="cas-number" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="unii" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="average-mass" type="xs:float" minOccurs="0"/&gt;
  &gt;             &lt;xs:element name="monoisotopic-mass" type="xs:float" minOccurs="0"/&gt;
  &gt;             &lt;xs:element name="state" type="state-type" minOccurs="0"/&gt;
  &gt;             &lt;xs:element name="groups" type="group-list-type"/&gt;
  &gt;             &lt;xs:element name="general-references" type="reference-list-type"/&gt;
  &gt;             &lt;xs:element name="synthesis-reference" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="indication" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="pharmacodynamics" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="mechanism-of-action" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="toxicity" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="metabolism" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="absorption" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="half-life" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="protein-binding" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="route-of-elimination" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="volume-of-distribution" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="clearance" type="xs:string"/&gt;
  &gt;             &lt;xs:element name="classification" type="classification-type" minOccurs="0"/&gt;
  &gt;             &lt;xs:element name="salts" type="salt-list-type"/&gt;
  &gt;             &lt;xs:element name="synonyms" type="synonym-list-type"/&gt;
  &gt;             &lt;xs:element name="products" type="product-list-type"/&gt;
  &gt;             &lt;xs:element name="international-brands" type="international-brand-list-type"/&gt;
  &gt;             &lt;xs:element name="mixtures" type="mixture-list-type"/&gt;
  &gt;             &lt;xs:element name="packagers" type="packager-list-type"/&gt;
  &gt;             &lt;xs:element name="manufacturers" type="manufacturer-list-type"/&gt;
  &gt;             &lt;xs:element name="prices" type="price-list-type"/&gt;
  &gt;             &lt;xs:element name="categories" type="category-list-type"/&gt;
  &gt;             &lt;xs:element name="affected-organisms" type="affected-organism-list-type"/&gt;
  &gt;             &lt;xs:element name="dosages" type="dosage-list-type"/&gt;
  &gt;             &lt;xs:element name="atc-codes" type="atc-code-list-type"/&gt;
  &gt;             &lt;xs:element name="ahfs-codes" type="ahfs-code-list-type"/&gt;
  &gt;             &lt;xs:element name="pdb-entries" type="pdb-entry-list-type"/&gt;
  &gt;             &lt;xs:element name="fda-label" type="xs:anyURI" minOccurs="0"/&gt;
  &gt;             &lt;xs:element name="msds" type="xs:anyURI" minOccurs="0"/&gt;
  &gt;             &lt;xs:element name="patents" type="patent-list-type"/&gt;
  &gt;             &lt;xs:element name="food-interactions" type="food-interaction-list-type"/&gt;
  &gt;             &lt;xs:element name="drug-interactions" type="drug-interaction-list-type"/&gt;
  &gt;             &lt;xs:element minOccurs="0" name="sequences" type="sequence-list-type"/&gt;
  &gt;             &lt;xs:element minOccurs="0" name="calculated-properties" type="calculated-property-list-type"/&gt;
  &gt;             &lt;xs:element name="experimental-properties" type="experimental-property-list-type"/&gt;
  &gt;             &lt;xs:element name="external-identifiers" type="external-identifier-list-type"/&gt;
  &gt;             &lt;xs:element name="external-links" type="external-link-list-type"/&gt;
  &gt;             &lt;xs:element name="pathways" type="pathway-list-type"/&gt;
  &gt;             &lt;xs:element name="reactions" type="reaction-list-type"/&gt;
  &gt;             &lt;xs:element name="snp-effects" type="snp-effect-list-type"/&gt;
  &gt;             &lt;xs:element name="snp-adverse-drug-reactions" type="snp-adverse-drug-reaction-list-type"/&gt;
  &gt;             &lt;xs:element name="targets" type="target-list-type"/&gt;
  &gt;             &lt;xs:element name="enzymes" type="enzyme-list-type"/&gt;
  &gt;             &lt;xs:element name="carriers" type="carrier-list-type"/&gt;
  &gt;             &lt;xs:element name="transporters" type="transporter-list-type"/&gt;
  &gt;         &lt;/xs:sequence&gt;
  </code></pre>
  
  <p>This is only a part of it. It's a huge file. Any kind of help/guidance is much appreciated.</p>