SQLite query to read an XML file
I want a SQLite query for reading my XML file and then I want a function that will convert my XML file to an SQLite t开发者_如何转开发able.
There's no query or function to do this.
The way to go is to write a stylesheet (.xsl
) that produces output consumable by sqlite's .import
command.
There is no way to read XML using SQLite commands, but you can create your own function which takes an XML path as parameter. Follow these steps, assuming that you are using .NET, and you know the structure of the XML (nodes, elements and attributes):
- Load the XML in
XmlDocument
, so that you can read the XML elements. - Iterate one
for
loop for number of times equal to the node count in XML. - Build one dynamic string which prepares the
insert
command in SQLite, with all the required node values as column values. - Execute the dynamically prepared
insert
command in SQlite.
精彩评论