读入dataset:
XmlDataDocument xmldoc=new XmlDataDocument();
xmldoc.DataSet.ReadXml(Server.MapPath("test.xml"));
至于按指定条件读取,就在xmldoc.DataSet里操作吧
XmlDataDocument xmldoc=new XmlDataDocument();
xmldoc.DataSet.ReadXml(Server.MapPath("test.xml"));
至于按指定条件读取,就在xmldoc.DataSet里操作吧
XmlTextReader reader=new XmlTextReader(Server.MapPath("test.xml"));
while(reader.Read())
{
//readdata
}
reader=new XmlTextReader(Server.MapPath("test.xml"));
try
{
while(reader.Read())
{
switch(reader.NodeType)
{
case XmlNodeType.Element:
if(reader.HasAttributes)
{
for(i=0;i<reader.AttributeCount;i++)
{
Response.Write(reader.GetAttribute(i)+" ");
}
Response.Write("<br>");
}
break;
case XmlNodeType.Text:
Response.Write(reader.Value+"<br>");
break;
}
}
}
catch
{
Response.Write("Error accessing XML file");
}
finally
{
reader.Close();
}
如下提供一段示例程序,供您参考:
程序的主要功能是:查找符合条件的XmlNode,写入DataTable中,然后将此DataTable添加到DataSet中(ds.Tables.Add(tb);),最后在DataGrid中显示table表中的数据记录。
private void button1_Click(object sender, System.EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load("test.xml");
//Select the value.
XmlNodeList nodeList;
XmlElement root = doc.DocumentElement;
nodeList = root.SelectNodes("/Contracts/Contract[@id='2']"); // Create DataSet and DataTable
DataSet ds = new DataSet();
DataColumn col = null;
DataTable tb = new DataTable("Contracts"); col = new DataColumn("Address", typeof(System.String));
tb.Columns.Add(col);
col.Unique = false;
col = tb.Columns.Add("Phone", typeof(System.String)); DataRow aRow = null;
foreach (XmlNode id in nodeList)
{
aRow = tb.NewRow();
aRow[0] = id.FirstChild.InnerText;
aRow[1] = id.FirstChild.NextSibling.InnerText;
tb.Rows.Add(aRow);
}
// Add the DataTable to the DataSet.
ds.Tables.Add(tb);
// Show DataGrid
dataGrid1.DataSource = ds.Tables["Contracts"].DefaultView;
}
}
— 微软全球技术中心 VB支持中心本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
如下提供一段示例程序,供您参考:
程序的主要功能是:查找符合条件的XmlNode,写入DataTable中,然后将此DataTable添加到DataSet中(ds.Tables.Add(tb);),最后在DataGrid中显示table表中的数据记录。
private void button1_Click(object sender, System.EventArgs e)
{
XmlDocument doc = new XmlDocument();
doc.Load("test.xml");
//Select the value.
XmlNodeList nodeList;
XmlElement root = doc.DocumentElement;
nodeList = root.SelectNodes("/Contracts/Contract[@id='2']"); // Create DataSet and DataTable
DataSet ds = new DataSet();
DataColumn col = null;
DataTable tb = new DataTable("Contracts"); col = new DataColumn("Address", typeof(System.String));
tb.Columns.Add(col);
col.Unique = false;
col = tb.Columns.Add("Phone", typeof(System.String)); DataRow aRow = null;
foreach (XmlNode id in nodeList)
{
aRow = tb.NewRow();
aRow[0] = id.FirstChild.InnerText;
aRow[1] = id.FirstChild.NextSibling.InnerText;
tb.Rows.Add(aRow);
}
// Add the DataTable to the DataSet.
ds.Tables.Add(tb);
// Show DataGrid
dataGrid1.DataSource = ds.Tables["Contracts"].DefaultView;
}
}
— 微软全球技术中心 VB支持中心本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。
为了为您创建更好的讨论环境,请参加我们的用户满意度调查(http://support.microsoft.com/directory/worldwide/zh-cn/community/survey.asp?key=(S,49854782))。
contracts.contract怎么解释?