我已经通过将SQLite数据库导出到c#.net中生成了一个XML文件。
<root>
<name1>
<names>
<id>5</id>
<from>Germany</from>
<to>France</to>
<through>
<via>
<id>7</id>
<routeNo>5<routeNo>
<route>Vienna<route>
</via>
</through>
</names>
<names>
<id>10</id>
<from>US</from>
<to>Canada</to>
<through>
<via>
<id>8</id>
<routeNo>10<routeNo>
<route>Mexico<route>
</via>
</through>
</names>
</name1>
</root>
然后我把上面的xml转换成这样一个XML文件
<names id="5" from="Germany" to="France">
<through id="9" routeNo="5" route="Vienna" />
<through id="10" routeNo="5" route="russia" />
</names>
我已经使用以下代码将此XML文件导入到SQLite数据库中:
var sqlite_conn = new SQLiteConnection(
"Data Source=SGLight_empty.fmeda;Version=3;New=True;Compress=True;");
NDbUnit.Core.INDbUnitTest sqliteDatabase
= new NDbUnit.Core.SqlLite.SqlLiteUnitTest(sqlite_conn);
sqliteDatabase.ReadXmlSchema("myXSD.xsd");
sqliteDatabase.ReadXml("myXML.xml");
sqliteDatabase.PerformDbOperation(NDbUnit.Core.DbOperationFlag.CleanInsertIdentity);
导入适用于普通XML文件。
- 问题是我无法导入从普通XML转换而来的平面XML文件。
- 有谁能帮我修改一下,这样我就可以从平面XML导入数据了?
1条答案
按热度按时间dzhpxtsq1#
需要考虑的一个问题是,即使为扁平化的XML提供了正确的XSD,SQLite是否能够识别XML并将其与生成完整XML的数据库模式匹配。
也就是说,Windows SDK附带了一个xsd工具,可以从任意XML文件推断出XSD。我将“平面”xml复制到一个名为temp.xml的文件中,运行
xsd temp.xml
,并收到以下XSD定义: