Import XML file to create DB Schema and enter information
I have an XML file from a few datasets which I need to store in a Relational DB, say MySQL. The DB schema shld be created based on the fields of the XML file automatically. What is the best way to do this? I am a 开发者_StackOverflow中文版novice in terms of XML handling and parsing and will appreciate tutorial links if possible.
This is not a straightforward issue. XML and relational databases are very dissimilar storage systems.
XML is very flexible in the data it stores. It is hierarchical as opposed to relational and, in absence of a matching XSD schema file, doesn't care what attributes exist in what elements. This is very different from a relational database that requires a table and column structure and cannot handle novel (for instance) novel columns in a given table. If the XML data originated in a relational database it may have a structure more similar to a relation database structure but it also may not (it may have been converted from a relation toa hierarchical representation, for instance).
XML does not contain any data typing information. All fields are store as text, with non-text values serialized into a text format. Therefore, much of the information you need to construct a database schema is missing.
XML also does not have relational integrity constraints. You can "guess" at some of them by looking at the hierarchical representation structure of the XML file, but you can't know what constraints must be enforced.
精彩评论