新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   XML论坛     >>W3CHINA.ORG讨论区<<     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> Oracle, SQL Server与XML,XML在数据挖掘中的应用, PMML.
    [返回] W3CHINA.ORG讨论区 - 语义网·描述逻辑·本体·RDF·OWLXML.ORG.CN讨论区 - 高级XML应用『 XML 与 数据库 』 → [求助]谁会SQL数据库转成XML格式的文档 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 6685 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: [求助]谁会SQL数据库转成XML格式的文档 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     playboylinlin 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:0
      积分:54
      门派:XML.ORG.CN
      注册:2005/5/23

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给playboylinlin发送一个短消息 把playboylinlin加入好友 查看playboylinlin的个人资料 搜索playboylinlin在『 XML 与 数据库 』的所有贴子 引用回复这个贴子 回复这个贴子 查看playboylinlin的博客楼主
    发贴心情 [求助]谁会SQL数据库转成XML格式的文档

    本人现在急需把SQL数据库的东西转成XML格式的文档,这样的一个工具的源代码,那位大哥或大姐,会的话帮小弟编一个 ,语言没有限制,只要有这个功能.先谢谢各位了
    本人QQ:9472398

       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/5/23 16:26:00
     
     canxing 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(高数修炼中)
      文章:14
      积分:111
      门派:XML.ORG.CN
      注册:2005/1/13

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给canxing发送一个短消息 把canxing加入好友 查看canxing的个人资料 搜索canxing在『 XML 与 数据库 』的所有贴子 引用回复这个贴子 回复这个贴子 查看canxing的博客2
    发贴心情 
    我也想要了……
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/5/25 9:42:00
     
     keeponline 美女呀,离线,快来找我吧!天秤座1975-10-21
      
      
      威望:4
      等级:大四寒假(收到IBM的Offer啦)
      文章:190
      积分:1150
      门派:W3CHINA.ORG
      注册:2005/1/20

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给keeponline发送一个短消息 把keeponline加入好友 查看keeponline的个人资料 搜索keeponline在『 XML 与 数据库 』的所有贴子 引用回复这个贴子 回复这个贴子 查看keeponline的博客3
    发贴心情 
    我也想要

    ----------------------------------------------
    买书不等于读书,读书不一定要买书。

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/6/11 12:51:00
     
     jx27 帅哥哟,离线,有人找我吗?
      
      
      等级:大二期末(汇编考了97分!)
      文章:37
      积分:447
      门派:XML.ORG.CN
      注册:2005/6/15

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给jx27发送一个短消息 把jx27加入好友 查看jx27的个人资料 搜索jx27在『 XML 与 数据库 』的所有贴子 引用回复这个贴子 回复这个贴子 查看jx27的博客4
    发贴心情 
    呵呵,得用PHP。

    没编过,不好意思,帮不到你

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/6/17 18:50:00
     
     webdev 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:14
      积分:114
      门派:XML.ORG.CN
      注册:2004/10/27

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给webdev发送一个短消息 把webdev加入好友 查看webdev的个人资料 搜索webdev在『 XML 与 数据库 』的所有贴子 引用回复这个贴子 回复这个贴子 查看webdev的博客5
    发贴心情 
    自己写个啊,取得表的字段名和字段值,然后封装就行了,不过外围的标签你还是需要自己定义的。
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/6/27 13:08:00
     
     315zxl 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(高数修炼中)
      文章:15
      积分:120
      门派:XML.ORG.CN
      注册:2005/8/5

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给315zxl发送一个短消息 把315zxl加入好友 查看315zxl的个人资料 搜索315zxl在『 XML 与 数据库 』的所有贴子 引用回复这个贴子 回复这个贴子 查看315zxl的博客6
    发贴心情 
    自己写一个呀!!
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/8/5 16:25:00
     
     xcccb 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:0
      积分:71
      门派:XML.ORG.CN
      注册:2005/5/8

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给xcccb发送一个短消息 把xcccb加入好友 查看xcccb的个人资料 搜索xcccb在『 XML 与 数据库 』的所有贴子 引用回复这个贴子 回复这个贴子 查看xcccb的博客7
    发贴心情 
    用asp.net来写:
    sqlcommand.commandText="select * from employee for xml auto,xmldata"
    sqlcommand.commandType = CommandType.Text
    dim xmlReader as xml.xmlTextReader
    xmlReader = sqlcommand.executexmlreader
    dataset.readxml(xmlreader,xmlreadmode.fragment)
    dim filename as filestream = new filestream("test.xml",filemode.create)
    ds.writexml("test.xml")
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/9/5 18:46:00
     
     弄清影 美女呀,离线,快来找我吧!天蝎座1983-10-30
      
      
      等级:大一(高数修炼中)
      文章:9
      积分:106
      门派:W3CHINA.ORG
      注册:2005/9/23

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给弄清影发送一个短消息 把弄清影加入好友 查看弄清影的个人资料 搜索弄清影在『 XML 与 数据库 』的所有贴子 引用回复这个贴子 回复这个贴子 查看弄清影的博客8
    发贴心情 

    首先建立与数据库的连接,本例子用SQL Server中的Northwind数据库中的Supplier表,为Supplier表创建存储过程命名为GetSupplierXml
    seleclt............
    for xml auto

    用.net平台C# 语言
    首先创建SupplierListDB组件如下:
    using System;
    using System.Collections;
    using System.Data;
    using System.Data.OleDb;
    using System.Data.SqlClient;
    using System.Xml;

    namespace SupplierListDB
    {
      public class SupplierList
      {
    //连接数据库
        private String m_ConnectString;
        public SupplierList(String ConnectString)
        {
          m_ConnectString = ConnectString;
        }
        public DataSet GetSuppliersDataSet()
        {

    //调用存储过程String strQuery = "GetSupplierList";

          OleDbConnection objConnect = new OleDbConnection(m_ConnectString);
          OleDbDataAdapter objAdapter = new OleDbDataAdapter(strQuery, objConnect);
          DataSet objDataSet = new DataSet();
          try
          {

            // get the data into a table named "Suppliers" in the DataSet
            objAdapter.Fill(objDataSet, "Suppliers");
            // return the DataSet object to the calling routine
            return objDataSet;
          }
          catch (Exception objErr)
          {
            throw (objErr);
          }
        }
        public OleDbDataReader GetSuppliersDataReader()
        {

          // declare a String containing the stored procedure name
          String strQuery = "GetSupplierList";
          // create a new Connection object using connection string
          OleDbConnection objConnect = new OleDbConnection(m_ConnectString);
          // create new Command using stored proc name and Connection
          OleDbCommand objCommand = new OleDbCommand(strQuery, objConnect);
          try
          {

            // 打开连接
            objConnect.Open();
            // execute the stored proc to initialize the DataReader
            // connection will be closed when DataReader goes out of scope
            return objCommand.ExecuteReader(CommandBehavior.CloseConnection);
          }
          catch (Exception objErr)
          {
            throw (objErr);
          }
        }
          // method to return an XML document (as a String) containing
        // a full list of supplier details from database
        public String GetSuppliersXml(Boolean IncludeSchema)
        {

          // declare a String containing the stored procedure name
          String strQuery = "GetSupplierList";
          // create a new Connection object using connection string
          OleDbConnection objConnect = new OleDbConnection(m_ConnectString);
          // create new DataAdapter using stored proc name and Connection
          OleDbDataAdapter objAdapter = new OleDbDataAdapter(strQuery, objConnect);
          // create a new DataSet object to hold the results
          DataSet objDataSet = new DataSet();
          // declare an empty String to hold the results
          String strXml = String.Empty;
          try
          {
            // get the data into a table named "Suppliers" in the DataSet
            objAdapter.Fill(objDataSet, "Suppliers");
            // get schema if ( specif (ied in optional method parameter
            if (IncludeSchema == true)
              strXml = objDataSet.GetXmlSchema() + (char)13 + (char)10 + (char)13 + (char)10;
            // get XML data and append to String
            strXml += objDataSet.GetXml();
            // return the XML string to the calling routine
            return strXml;
          }
          catch (Exception objErr)
          {
            throw (objErr);
          }
        }
        // ----------------------------------------------------

        // method to return an XmlDocument object containing
        // a full list of supplier details from database
        public XmlDocument GetSuppliersXmlDocument()
        {

          // declare a String containing the stored procedure name
          String strQuery = "GetSupplierList";

          // create a new Connection object using connection string
          OleDbConnection objConnect = new OleDbConnection(m_ConnectString);

          // create new DataAdapter using stored proc name and Connection
          OleDbDataAdapter objAdapter = new OleDbDataAdapter(strQuery, objConnect);

          // create a new DataSet object to hold the results
          DataSet objDataSet = new DataSet();

          try
          {

            // get the data into a table named "Suppliers" in the DataSet
            objAdapter.Fill(objDataSet, "Suppliers");

            // create a new XmlDataDocument object based on the DataSet
            XmlDataDocument objXmlDataDoc = new XmlDataDocument(objDataSet);

            // return it an XmlDocument object to the calling routine
            return (XmlDocument)objXmlDataDoc;
          }
          catch (Exception objErr)
          {
            throw (objErr);
          }
        }

        // method to return an XML document (as a String) containing
        // a full list of supplier details from database, and using
        // a SQL Server XML technology (FOR XML) query
        public String GetSuppliersSqlXml()
        {

          // declare a String containing the SQL-XML stored proc to execute
          String strQuery = "GetSupplierXml";

          // create a new Connection object using connection string
          SqlConnection objConnect = new SqlConnection(m_ConnectString);

          // create new Command using stored proc name and Connection
          SqlCommand objCommand = new SqlCommand(strQuery, objConnect);

          // create a variable to hold an XmlTextReader object
          XmlTextReader objReader = null;

          String strXml = String.Empty;
          Char QUOT = (char)34;
          try
          {

            // open connection to the database
            objConnect.Open();

            // execute the stored proc to initialize the XmlTextReader
            objReader = (XmlTextReader) objCommand.ExecuteXmlReader();

            // create the document prolog
            DateTime datToday = DateTime.Now;
            strXml = "<?xml version=" + QUOT + "1.0" + QUOT + "?>"
              + "<!-- Created: " + datToday.ToString("d") + " -->"
              + "<SupplierList>";

            // read the first result row and ) read remainder
            objReader.ReadString();
            strXml += objReader.GetRemainder().ReadToEnd();

            // add the document epilog
            strXml += "</SupplierList>";
          }
          catch (Exception objErr)
          {
            throw (objErr);
          }
          finally
          {
            // close connection and destroy reader object
            objConnect.Close();
            objReader = null;
          }
          // return the XML document object to the calling routine
          return strXml;
        }
        // ----------------------------------------------------

        // method to return an Array containing the full
        // name and address details of suppliers from the database
        public String[,] GetSuppliersArray(ref int MaximumRowNumber)
        {

          // declare a String containing the stored procedure name
          String strQuery = "GetSupplierList";

          // create a new Connection object using connection string
          OleDbConnection objConnect = new OleDbConnection(m_ConnectString);

          // create new Command using stored proc name and Connection
          OleDbCommand objCommand = new OleDbCommand(strQuery, objConnect);

          // create a variable to hold a DataReader object
          OleDbDataReader objReader = null;

          try
          {

            // open connection to the database
            objConnect.Open();

            // execute query to initialize DataReader object
            // connection will be closed when DataReader goes out of scope
            objReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection);

            // get the index of the last column within the data
            int intLastColIndex = objReader.FieldCount;

            // declare a variable to hold the result array
            String[,] arrValues = new String[intLastColIndex, MaximumRowNumber];

            int intRowCount = 0;   // to hold number of rows returned
            int intCol;            // to hold the column iterator

            // iterate through rows by calling Read method until false
            while (objReader.Read() && intRowCount < MaximumRowNumber)
            {

              // store column values strings in result array
              for (intCol = 0; intCol < intLastColIndex; intCol++)
                arrValues[intCol, intRowCount] = (String) objReader[intCol];

              // increment number of rows found
              intRowCount++;

            }

            objReader = null;     // finished with DataReader

            // set Ref parameter value for number of rows in Array
            MaximumRowNumber = intRowCount - 1;

            return arrValues;   // and return array to the calling routine
          }
          catch (Exception objErr)
          {
            throw (objErr);
          }
        }
        // ----------------------------------------------------

        // method to return an ArrayList containing just the
        // name of each of the suppliers in the database
        public ArrayList GetSuppliersArrayList()
        {

          // declare a String containing the stored procedure name
          String strQuery = "GetSupplierName";

          // create a new Connection object using connection string
          OleDbConnection objConnect = new OleDbConnection(m_ConnectString);

          // create new Command using stored proc name and Connection
          OleDbCommand objCommand = new OleDbCommand(strQuery, objConnect);

          // create a variable to hold a DataReader object
          OleDbDataReader objReader = null;

          try
          {

            // open connection to the database
            objConnect.Open();

            // execute query to initialize DataReader object
            // connection will be closed when DataReader goes out of scope
            objReader = objCommand.ExecuteReader(CommandBehavior.CloseConnection);

            // create a new ArrayList object
            ArrayList arrValues = new ArrayList();

            // iterate through rows by calling Read method until false
            while (objReader.Read())
              arrValues.Add(objReader.GetString(0));

            objReader = null;     // finished with DataReader

            return arrValues;   // return ArrayList to the calling routine
          }
          catch (Exception objErr)
          {
            throw (objErr);
          }
        }
        // ----------------------------------------------------

      }
    }

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/9/23 13:34:00
     
     弄清影 美女呀,离线,快来找我吧!天蝎座1983-10-30
      
      
      等级:大一(高数修炼中)
      文章:9
      积分:106
      门派:W3CHINA.ORG
      注册:2005/9/23

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给弄清影发送一个短消息 把弄清影加入好友 查看弄清影的个人资料 搜索弄清影在『 XML 与 数据库 』的所有贴子 引用回复这个贴子 回复这个贴子 查看弄清影的博客9
    发贴心情 

    不好意思,上次代码有冗余,
    用.net平台C# 语言
    首先创建SupplierListDB数据访问组件如下:
    using System;
    using System.Collections;
    using System.Data;
    using System.Data.OleDb;
    using System.Data.SqlClient;
    using System.Xml;

    namespace SupplierListDB
    {
      public class SupplierList
      {
    //连接数据库
        private String m_ConnectString;
        public SupplierList(String ConnectString)
        {
          m_ConnectString = ConnectString;
        }
        public DataSet GetSuppliersDataSet()
        {

    //调用存储过程String strQuery = "GetSupplierList";

          OleDbConnection objConnect = new OleDbConnection(m_ConnectString);
          OleDbDataAdapter objAdapter = new OleDbDataAdapter(strQuery, objConnect);
          DataSet objDataSet = new DataSet();
          try
          {

            // get the data into a table named "Suppliers" in the DataSet
            objAdapter.Fill(objDataSet, "Suppliers");
            // return the DataSet object to the calling routine
            return objDataSet;
          }
          catch (Exception objErr)
          {
            throw (objErr);
          }
    // method to return an XML document (as a String) containing
        // a full list of supplier details from database, and using
        // a SQL Server XML technology (FOR XML) query
        public String GetSuppliersSqlXml()
        {

          // declare a String containing the SQL-XML stored proc to execute
          String strQuery = "GetSupplierXml";

          // create a new Connection object using connection string
          SqlConnection objConnect = new SqlConnection(m_ConnectString);

          // create new Command using stored proc name and Connection
          SqlCommand objCommand = new SqlCommand(strQuery, objConnect);

          // create a variable to hold an XmlTextReader object
          XmlTextReader objReader = null;

          String strXml = String.Empty;
          Char QUOT = (char)34;
          try
          {

            // open connection to the database
            objConnect.Open();

            // execute the stored proc to initialize the XmlTextReader
            objReader = (XmlTextReader) objCommand.ExecuteXmlReader();

            // create the document prolog
            DateTime datToday = DateTime.Now;
            strXml = "<?xml version=" + QUOT + "1.0" + QUOT + "?>"
              + "<!-- Created: " + datToday.ToString("d") + " -->"
              + "<SupplierList>";

            // read the first result row and ) read remainder
            objReader.ReadString();
            strXml += objReader.GetRemainder().ReadToEnd();

            // add the document epilog
            strXml += "</SupplierList>";
          }
          catch (Exception objErr)
          {
            throw (objErr);
          }
          finally
          {
            // close connection and destroy reader object
            objConnect.Close();
            objReader = null;
          }
          // return the XML document object to the calling routine
          return strXml;
        }
        }
    以下是ASP.NET代码
    <%@Page Language="C#" %>
    <%@Import Namespace="SupplierListDB" %>

    <!------------------ HTML page content --------------------->

    <html>
    <head>
    <title>Supplier List : XML Document from Relational Database</title>
    <!-- #include file="../global/style.inc" -->
    </head>
    <body>

    <div class="heading">Supplier List : XML Document from Relational Database</div>

    <div align="right" class="cite">
    [<a href="../global/viewsource.aspx?compsrc=get-supplier-data.cs">view page source</a>]<br />
    [<a href="viewxml.aspx?doc=GetSuppliersXml">view XML document</a>]<br />
    [<a href="viewxml.aspx?doc=GetSuppliersXmlStyle">view XSLT sylesheet</a>]
    </div><br />

    <asp:Label id="lblMessage" runat="server" />
    <asp:Xml id="xmlResult" runat="server" /><br />

    <!-- #include file="../global/foot.inc" -->
    </body>
    </html>

    <!-------------- server-side script section ---------------->

    <script Language="C#" runat="server">

    void Page_Load() {

      // get connection string from web.config
      String strConnect = ConfigurationSettings.AppSettings["NorthwindConnectString"];

      try {

        // create an instance of the data access component
        SupplierList objSupplierList = new SupplierList(strConnect);

        // call the method to return the data as an Xml String and
        // specify false as no schema required
        // assign it to the Xml Server Control
        xmlResult.DocumentContent = objSupplierList.GetSuppliersXml(false);

        // specify path to XSLT stylesheet that transforms XML for display
        xmlResult.TransformSource = "supplier-list-style.xsl";
      }
      catch (Exception objErr) {

        // there was an error and no data will be returned
        lblMessage.Text = "ERROR: No data returned. " + objErr.Message;
      }
    }
    </script>

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2005/9/23 13:38:00
     
     GoogleAdSense天蝎座1983-10-30
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 XML 与 数据库 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/11/23 19:12:38

    本主题贴数9,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    250.000ms