日期:2014-05-18  浏览次数:21270 次

C# dataset!!!!
DataSet result = new DataSet();
string xml=result.GetXml();

以下是xml的值,要怎么能得到各个节点的值
<NewDataSet>
  <Weather>
  <Date>2012年05月02日</Date>
  <Week>星期三(Wed)</Week>
  <Weather>Mostly Sunny</Weather>
  <Tlow>18.3℃</Tlow>
  <Thigh>28.3℃</Thigh>
  </Weather>
  <Weather>
  <Date>2012年05月03日</Date>
  <Week>星期四(Thu)</Week>
  <Weather>Mostly Cloudy</Weather>
  <Tlow>18.9℃</Tlow>
  <Thigh>28.3℃</Thigh>
  </Weather>
</NewDataSet>

------解决方案--------------------
Xmldocument
http://msdn.microsoft.com/zh-cn/library/system.xml.xmldocument.aspx
或者用
Linq to Xml
http://topic.csdn.net/u/20120421/20/7c878b85-9f8f-4bfb-b66a-232d9db421b7.html
------解决方案--------------------
C# code
        /// <summary>
        /// 获取指定节点的值
        /// </summary>
        /// <param name="strFileName">文件路径</param>
        /// <param name="nodeName">节点名称</param>
        /// <param name="value">设置后的值</param>
        /// <param name="nodeDir">指定节点所在的节点目录</param>
        /// <returns></returns>
        public static string GetNodeValue(string strFileName, string nodeName, string nodeDir)
        {
            string value = null;
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(strFileName);

                XmlNodeList nodeList = xmlDoc.SelectSingleNode(nodeDir).ChildNodes;//获取bookstore节点的所有子节点 

                foreach (XmlNode xn in nodeList)    //遍历所有子节点 
                {
                    XmlElement xe = (XmlElement)xn;  //将子节点类型转换为XmlElement类型 

                    if (xe.Name == nodeName)
                    {
                        value = xe.InnerText.Trim();

                        break;
                    }
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }

            return value;
        }

        /// <summary>
        /// 获取指定节点下面对应属性的值
        /// </summary>
        /// <param name="strFileName">文件路径</param>
        /// <param name="nodeName">节点名称</param>
        /// <param name="nodeDir">指定节点所在的节点目录</param>
        /// <param name="attribute">节点对应的属性名称</param>
        /// <returns></returns>
        public static string GetNodeValue(string strFileName, string nodeName, string nodeDir, string attribute)
        {
            string value = null;
            try
            {
                XmlDocument xmlDoc = new XmlDocument();
                xmlDoc.Load(strFileName);

                XmlNodeList nodeList = xmlDoc.SelectSingleNode(nodeDir).ChildNodes;//获取bookstore节点的所有子节点 

                foreach (XmlNode xn in nodeList)    //遍历所有子节点 
                {
                    XmlElement xe = (XmlElement)xn;  //将子节点类型转换为XmlElement类型 

                    if (xe.Name == nodeName)
                    {
                        //value = xe.InnerText.Trim();
                        value = (xe).Attributes[attribute].Value;
                        break;
                    }
                }
            }
            catch (Exception exp)
            {
                throw exp;
            }

            return value;
        }

------解决方案--------------------
C# code

 protected void Page_Load(object sender, EventArgs e)
        {
            string serverpath