这个XML怎么转成DataSet,本人是菜鸟啊! 本帖最后由 sb19871023 于 2009-07-27 14:15:04 编辑 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 就是直接用readxml 就可以了 只是可能在不同的table里 给你个关于XML的类 你看看using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security;using System.Web.UI;using System.Web.UI.WebControls;using System.Web.UI.WebControls.WebParts;using System.Web.UI.HtmlControls;using System.Data.SqlClient;using System.Xml;using System.Collections; /// <summary>/// TXml 的摘要说明/// </summary>public class TXml{ /// <summary> /// XML操作类 /// </summary> public TXml() { // // TODO: // } XmlDocument XD = new XmlDocument(); /// <summary> /// 在xml文件内查询数据 /// </summary> /// <param name="XmlFilePath">Xml文件</param> /// <param name="XmlPath">XPath条件</param> /// <returns>返回查询到的内容</returns> public XmlNode DataFind(string XmlFilePath, string XmlPath) { XD.Load(XmlFilePath); return XD.SelectSingleNode(XmlPath); } /// <summary> /// 保存数据 /// </summary> /// <param name="XmlFilePath">Xml文件</param> public void Save(string XmlFilePath) { XD.Save(XmlFilePath); } /// <summary> /// 获得子节点个数 /// </summary> /// <param name="XmlFilePath">Xml路径</param> /// <param name="XmlPath">XPath条件</param> /// <returns></returns> public int GetLineCount(string XmlFilePath, string XmlPath) { XmlNode Xl = DataFind(XmlFilePath, XmlPath); return Xl == null ? 0 : Xl.ChildNodes.Count; } /// <summary> /// 自定义数据绑定 /// </summary> /// <param name="XmlFilePath">xml文件路径</param> /// <param name="XmlPath">XPath 搜索条件</param> /// <param name="SortKey">排序关键字</param> /// <returns>返回与DataSource相对应的借口</returns> public ICollection CreateDataSource(string XmlFilePath, string XmlPath, string SortKey) { DataTable dt = new DataTable(); DataRow dr; DataView dv = null; try { XD.Load(XmlFilePath); XmlNodeList xl = XD.SelectNodes(XmlPath); if (xl != null && xl.Count > 0) { int j; for (j = 0; j < xl[0].Attributes.Count; j++) { dt.Columns.Add(new DataColumn(xl[0].Attributes.Item(j).LocalName, typeof(string))); } dt.Columns.Add(new DataColumn(xl[0].LocalName, typeof(string))); for (int i = 0; i < xl.Count; i++) { dr = dt.NewRow(); for (j = 0; j < xl[i].Attributes.Count; j++) { dr[j] = xl[i].Attributes.Item(j).InnerText; } dr[j] = xl[i].InnerText; dt.Rows.Add(dr); } } dv = new DataView(dt); dv.Sort = SortKey; } catch { } return dv; } /// <summary> /// 通用CDATA数据写入 /// </summary> /// <param name="strFilePath">路径</param> /// <param name="strData">数据</param> /// <param name="strNote">注释</param> /// <param name="strXslFile">解释的xsl文件 可以不写</param> public void WriteXml(string strFilePath, string strData, string strNote, string strXslFile) { XmlTextWriter XmlFile = new XmlTextWriter(strFilePath, null); try { XmlFile.Formatting = Formatting.Indented; XmlFile.Indentation = 3; XmlFile.WriteStartDocument(); if (strXslFile != "") { XmlFile.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='" + strXslFile + "'"); } XmlFile.WriteComment("Create @" + DateTime.Now.ToString()); XmlFile.WriteComment(strNote); XmlFile.WriteStartElement("DB"); XmlFile.WriteCData(strData); XmlFile.WriteEndElement(); XmlFile.WriteEndDocument(); } catch { } XmlFile.Close(); }} 用了!不可以!提供的 Xml 实例是一个架构或包含内嵌架构。该类无法针对某架构来推断架构。报这个异常 ASP.NET MVC根据不同域名,调用不同“主题”的VIEW。可以吗? 有关GridView的DatakeyNames属性,怎么理解呢? 自动删除贴子 My God!CSDN的页面字体怎变成这个样子了?? 有同学研究过scorm标准的API开发吗? 新手問題 框架的问题 repeater 服务器标记格式不正确 当使用了showModalDialog打开的窗口后。。。 两台服务器之间的文件拷贝 用正则取值的问题 我做了个网站 www.81guomin.com 大家给点意见 一定给分
using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Xml;
using System.Collections; /// <summary>
/// TXml 的摘要说明
/// </summary>
public class TXml
{
/// <summary>
/// XML操作类
/// </summary>
public TXml()
{
//
// TODO:
//
} XmlDocument XD = new XmlDocument();
/// <summary>
/// 在xml文件内查询数据
/// </summary>
/// <param name="XmlFilePath">Xml文件</param>
/// <param name="XmlPath">XPath条件</param>
/// <returns>返回查询到的内容</returns>
public XmlNode DataFind(string XmlFilePath, string XmlPath)
{
XD.Load(XmlFilePath);
return XD.SelectSingleNode(XmlPath);
} /// <summary>
/// 保存数据
/// </summary>
/// <param name="XmlFilePath">Xml文件</param>
public void Save(string XmlFilePath)
{
XD.Save(XmlFilePath);
} /// <summary>
/// 获得子节点个数
/// </summary>
/// <param name="XmlFilePath">Xml路径</param>
/// <param name="XmlPath">XPath条件</param>
/// <returns></returns>
public int GetLineCount(string XmlFilePath, string XmlPath)
{
XmlNode Xl = DataFind(XmlFilePath, XmlPath);
return Xl == null ? 0 : Xl.ChildNodes.Count;
} /// <summary>
/// 自定义数据绑定
/// </summary>
/// <param name="XmlFilePath">xml文件路径</param>
/// <param name="XmlPath">XPath 搜索条件</param>
/// <param name="SortKey">排序关键字</param>
/// <returns>返回与DataSource相对应的借口</returns>
public ICollection CreateDataSource(string XmlFilePath, string XmlPath, string SortKey)
{
DataTable dt = new DataTable();
DataRow dr;
DataView dv = null; try
{
XD.Load(XmlFilePath); XmlNodeList xl = XD.SelectNodes(XmlPath); if (xl != null && xl.Count > 0)
{
int j;
for (j = 0; j < xl[0].Attributes.Count; j++)
{
dt.Columns.Add(new DataColumn(xl[0].Attributes.Item(j).LocalName, typeof(string)));
} dt.Columns.Add(new DataColumn(xl[0].LocalName, typeof(string))); for (int i = 0; i < xl.Count; i++)
{
dr = dt.NewRow();
for (j = 0; j < xl[i].Attributes.Count; j++)
{
dr[j] = xl[i].Attributes.Item(j).InnerText; }
dr[j] = xl[i].InnerText;
dt.Rows.Add(dr);
} }
dv = new DataView(dt);
dv.Sort = SortKey;
}
catch
{ }
return dv;
} /// <summary>
/// 通用CDATA数据写入
/// </summary>
/// <param name="strFilePath">路径</param>
/// <param name="strData">数据</param>
/// <param name="strNote">注释</param>
/// <param name="strXslFile">解释的xsl文件 可以不写</param>
public void WriteXml(string strFilePath, string strData, string strNote, string strXslFile)
{
XmlTextWriter XmlFile = new XmlTextWriter(strFilePath, null);
try
{
XmlFile.Formatting = Formatting.Indented;
XmlFile.Indentation = 3;
XmlFile.WriteStartDocument();
if (strXslFile != "")
{
XmlFile.WriteProcessingInstruction("xml-stylesheet", "type='text/xsl' href='" + strXslFile + "'");
}
XmlFile.WriteComment("Create @" + DateTime.Now.ToString());
XmlFile.WriteComment(strNote);
XmlFile.WriteStartElement("DB");
XmlFile.WriteCData(strData);
XmlFile.WriteEndElement();
XmlFile.WriteEndDocument();
}
catch
{ }
XmlFile.Close();
}
}