以文本方式查看主题

-  计算机科学论坛  (http://bbs.xml.org.cn/index.asp)
--  『 XML 与 数据库 』  (http://bbs.xml.org.cn/list.asp?boardid=17)
----  从Access (2003) 导入导出 XML  (http://bbs.xml.org.cn/dispbbs.asp?boardid=17&rootid=&id=25569)


--  作者:98900969r
--  发布时间:12/17/2005 1:54:00 PM

--  从Access (2003) 导入导出 XML
很多朋友关心如何从Access导入导出XML数据。而Access是低端数据库产品,XML功能不能说强,导入导出是可以的,但是得经由磁盘文件。下面两篇来自MSDN的文章比较详细的讲解了这个问题。

New XML Features in Microsoft Office Access 2003
Frank C. Rice
Microsoft Corporation
http://www.msdn.microsoft.com/office/understanding/xmloffice/articles/default.aspx?pull=/library/en-us/odc_ac2003_ta/html/odc_accessnewxmlfeatures.asp

Using the XML Features of the Access 2003 Object Model
Frank Rice
Microsoft Corporation
http://www.msdn.microsoft.com/office/understanding/xmloffice/articles/default.aspx?pull=/library/en-us/odc_ac2003_ta/html/odc_acxmlom.asp#odc_acxmlom_xml

可惜是英文的。由于没有时间,不能全部翻译。我这里只大略介绍一下。具体的,还请看原文。

简介
Access提供手工操作和编程两种方式来导入导出XML数据。头一篇介绍手工操作方法比较多,但也介绍了编程方法。后一篇则专门介绍编程方式。由于大家都是写程序的,这里也就只管程序方式的导入导出。

从Access2002开始,Access就提供了简单的导入导出功能。主要是两个过程,ImportXML和ExportXML。而2003中,ExportXML功能有了增强,它现在支持输出相关的表、排序和过滤。这是通过使用ExportXML的可选参数,OtherFlags,UseSort,UseFiler,和AdditionalData来完成的。

代码举例
Export Data, Schema, Formatting, and Related Tables to XML
(即输出数据、模式、格式以及相关表到XML)
这个例子输出一个名为Order的表以及跟它相关的表到一个XML。模式以及格式是另外输出到xsd和xsl文件的。例子很简单明了,无须过多解释。

Private Sub ExportRelTables()
   ' Purpose: Exports the Orders table as well as
   ' a number of related database to an XML file.
   ' XSD and XSL files are also created.

   Dim objAD As AdditionalData

   ' Create the AdditionalData object.
   Set objAD = Application.CreateAdditionalData

   ' Add the related tables to the object.
   With objAD
      .Add "Order Details"
      objAD(Item:="Order Details").Add "Order Details Details"
      .Add "Customers"
      .Add "Shippers"
      .Add "Employees"
      .Add "Products"
      objAD(Item:="Products").Add "Product Details"
      objAD(Item:="Products")(Item:="Product Details").Add _
         "Product Details Details"
      .Add "Suppliers"
      .Add "Categories"
   End With
   Application.ExportXml acExportTable, "Orders", _
       "C:\Orders.xml", "C:\OrdersSchema.xsd", _
       "C:\OrdersStyle.xsl", AdditionalData:= objAD
End Sub

文中还有输出报表到XML,导入XML数据及模式,以及用DOM和XSL做转换的例子。还给出了ExportXML,ImportXML,和TransformXML几个方法的详细信息。这里不一一介绍了。


W 3 C h i n a ( since 2003 ) 旗 下 站 点
苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
62.500ms