我能够为一百万条记录成功生成一个大型xml文件 使用以下代码。
cmd.CommandText = "SELECT PARTNER_NO FROM T1 WHERE YEAR LIKE '%2011-2012%'";
XmlWriter myWriter = XmlWriter.Create("C:/Test/BookInfo.xml")
myWriter.WriteStartDocument(true);
using(OracleDataReader reader = cmd.ExecuteReader(CommandBehavior.CloseConnection))
{
reader.FetchSize = reader.RowSize * 5000;
myWriter.WriteStartElement("master_table");
while(reader.Read())
{
myWriter.WriteStartElement("partner");
myWriter.WriteElementString("partner_no", reader[0].ToString());
myWriter.WriteElementString("id","0008");
myWriter.WriteEndElement();
}
}
myWriter.WriteEndDocument();
myWriter.Flush();
myWriter.Close();
cmd.Dispose()
这是我的xml看起来的样子:
我现在有了一个新的要求,即根据行数生成多个10,000个记录的xml文件。 有关于此的任何指示?我该怎么办呢?这需要在c#
上完成答案 0 :(得分:1)
您可以在单个SQL调用中执行此操作:
SQL> SELECT XMLSERIALIZE(CONTENT xmlelement("MASTER_TABLE",
2 xmlagg(xmlelement("PARTNER",
3 XMLELEMENT("PARTNER_NO",
4 partner_no),
5 XMLELEMENT("ID", '0008')
6 )
7 ))
8 INDENT) xmltxt
9 FROM t1
10 GROUP BY CEIL(ROWNUM/2)-- replace 2 by 10000
11 ;
XMLTXT
-------------------------------------------------------------------------------
<MASTER_TABLE>
<PARTNER>
<PARTNER_NO>00001</PARTNER_NO>
<ID>0008</ID>
</PARTNER>
<PARTNER>
<PARTNER_NO>00034</PARTNER_NO>
<ID>0008</ID>
</PARTNER>
</MASTER_TABLE>
<MASTER_TABLE>
<PARTNER>
<PARTNER_NO>00046</PARTNER_NO>
<ID>0008</ID>
</PARTNER>
<PARTNER>
<PARTNER_NO>00052</PARTNER_NO>
<ID>0008</ID>
</PARTNER>
</MASTER_TABLE>
进一步阅读: