且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

读取xml文件并导入数据集中所有数据的最快方法

更新时间:2023-01-21 11:36:01

对于大型xml文件,加载整个xml将是缓慢且低效的,这导致性能不佳。这是CP本身的一篇文章,它解决了这个问题:



http://www.codeproject.com/Articles/156982/How-to-Open-Large-XML-files-without-Loading- -XM.aspx [ ^ ]
For large xml files, loading the whole xml will be slow and inefficient which results in poor performance. Here is an article in CP itself which addressed this issue:

http://www.codeproject.com/Articles/156982/How-to-Open-Large-XML-files-without-Loading-the-XM.aspx[^]


请检查以下链接



在C#中使用XmlReader读取Xml [ ^ ]
Please check following link

Reading Xml with XmlReader in C#[^]


As一旦你定义了XML元素中使用的XML命名空间,就可以轻松导入它 - 没问题。



你需要让你的XML看起来像这样: br />


As soon as you define your XML namespace used in the XML elements, you can easily import this - no problem.

You need to have your XML look something like this:

<Catalog xmlns:dt="some-xml-namespace-here">
 <Rec>
   <ITEM dt:dt="string"/>
   <QTY dt:dt="string">1</QTY>
   <SUB dt:dt="string">1</SUB>
   <CATALOG dt:dt="string">ABC123</CATALOG>
  </Rec>
  .....
 </Catalog>



执行此操作后,您的两行代码就像魅力一样,数据导入,没问题(进入5个表格)在数据集内。


After I do this, your two lines of code work like a charm and the data gets imported, no problem (into 5 tables inside the Dataset.