cancel
Showing results for 
Search instead for 
Did you mean: 

XML / XSD Library for Python

Community Veteran
Posts: 5,237
Thanks: 1,321
Fixes: 31
Registered: 16-10-2014

XML / XSD Library for Python

I’ve been asked if I can build a parser that will take input from a set of CSV files and in conjunction with an XSD file generate the SQL needed to create tables and stored procedures to populate the table. I know from the name of the CSV file what the table should be called, so prepending Insert to that will give me the procedure name.

The CSV file only tells me the column name and description it doesn’t tell me its size or if there is a default value or what range of values a column can take but the XSD does.

So my question is, is there a python library that will allow me to search a schema file for that information? For example given this fragment of an XSD:

 <xs:simpleType name="FileNameType">
    <xs:restriction base="xs:string">
      <xs:maxLength value="60"/>
      <xs:minLength value="0"/>
    </xs:restriction>
  </xs:simpleType>
...
...

<xs:attribute name=“DataFile" type="FileTypeType" use="required"/>
...

When parsing the CSV file I want to look up the xs:attribute for the name = ‘DataFile’ (the column name) this would then return the entire attribute element. Once I have the attribute element I want to check if the use attribute exists and if it does what its value is.

I would then check for the existence of the type attribute and if it existed search the XSD for its definition. I then want to read the definition so I know that the column DataFile is :

CREATE TABLE …(
DATAFILE VARCHAR(60) ; — Name of Import File
…
)

If any one know of such a library then I’d appreciate your thoughts.