四种读取XML文档的方式

      .Net 2005-2-16 23:7
转贴,请标名出处!
本人随笔,望高人指教!
1,使用文件流对象的例子:
DataSet ds=new DataSet();
System.IO.FileStream fs=new System.IO.FileStream("abc.xml",System.IO.FileMode.Open);
//读取XML文档
ds.ReadXmlSchema(fs);
fs.Close();

2,使用文件名的例子:
DataSet ds=new DataSet();
ds.ReadXmlSchema("abc.xml");

3,使用StreamReader对象(TextReader的派生类)
DataSet ds=new DataSet();
System.IO.StreamReader sr=new System.IO.StreamReader("abc.xml");
sr.Close();

4,使用XmlTextReader(XmlReader的派生类)
DataSet ds=new DataSet();
System.IO.FileStream fs=new System.IO.FileStream("abc.xml",System.IO.FileMode.Open);
System.Xml.XmlTextReader xmlreader=new System.Xml.XmlTextReader(fs);
ds.ReadXmlSchema(xmlreader);
xmlreader.Close();
标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}