我从网上下载了flash+xml的网站模板,请问asp.net如何从数据库读取数据给以有的xml?

解决方案 »

  1.   

    你应该是要动态读取数据来修改相应的xml节点
      

  2.   

    貌似只能猜测了,你会不会读写XML,会的话,后台数据读出来要么是个dataTable ,要么是个list
    循环数据,然后创建xmlDocument 创建childNode 再添加innerText就可以了,网上随便找个操作XML的代码修改修改,就差不多了.
      

  3.   

    ds.WriteXML
    遍历数据集,修改XML或添加节点public static void Insert(string path, string node, string element, string attribute, string value)
      {
      try
      {
      XmlDocument doc = new XmlDocument();
      doc.Load(path);
      XmlNode xn = doc.SelectSingleNode(node);
      if (element.Equals(""))
      {
      if (!attribute.Equals(""))
      {
      XmlElement xe = (XmlElement)xn;
      xe.SetAttribute(attribute, value);
      }
      }
      else
      {
      XmlElement xe = doc.CreateElement(element);
      if (attribute.Equals(""))
      {
      xe.InnerText = value;
      }
      else
      {
      xe.SetAttribute(attribute, value);
      }
      xn.AppendChild(xe);
      }
      doc.Save(path);
      }
      catch { }
      }
      

  4.   

    从数据读取数据,然后加载到XML中。
      File.Delete(xpath);
    string strings = "<?xml version=\"1.0\" encoding=\"gb2312\"?><?xml-stylesheet type='text/xsl' href='dyrss.xsl' version='1.0'?><rss version=\"2.0\"><channel><title>标题</title><link>http://www.zn120.com/</link><description>最新聚合新闻列表</description>";
            StringBuilder builder = new StringBuilder();
            builder.Append(SQL查询语句);
            builder.Append("sql查询语句 ");
            DataTable table = SqlHelper.Query(builder.ToString()).Tables[0];
            for (int i = 0; i < table.Rows.Count; i++)
            {
                string str2 = strings;
                string[] strArray = new string[] { str2, "<item id=\"", (i + 1).ToString(), "\"><title><![CDATA[", table.Rows[i][1].ToString(), "]]></title><link>", rdCreat.getWWW(table.Rows[i]["Type1"].ToString()), "/new/new_", table.Rows[i][0].ToString(), ".shtml</link><description><![CDATA[ 【", DateTime.Parse(table.Rows[i][2].ToString()).ToShortDateString(), "】", table.Rows[i][7].ToString(), "]]>......</description><pubDate>", DateTime.Parse(table.Rows[i][2].ToString()).ToUniversalTime().ToString("r"), "</pubDate></item>" };
                strings = string.Concat(strArray);
            }
            strings = strings + "</channel></rss>";
            FileObj.WriteFile(xpath, strings);
      

  5.   

    这与后台给XML值没区别 只是 一个是 数据库过来的  一个是 前台过来的你先读取数据库的值  再赋值 给 XML