您的位置:首页 > 其它

XML和关系数据----从XML推断数据集映射

2006-12-06 19:34 399 查看

如何从 XML 推导出数据集映射

此示例阐释如何从 XML 数据创建数据集 (DataSet) 映射。此示例使用推理概念,由此可以使 XML 数据本身的实际结构成为关系架构的基础。然后,该示例创建表和列的关系结构,用来存储符合推导出的架构的数据集中的数据。





VB DataSetMapXMLData.aspx
[运行示例] | [查看源代码]
为了从 XML 数据结构推导出架构,以下示例代码说明应该如何使用 XmlReadMode 的 InferSchema 调用 DataSet.ReadXml。如果不指定一个 XmlReadMode,那么当数据集还没有架构,并且文档不包含内联架构时,ReadXml 方法将推导一个架构。

function doClick(index, numTabs, id) {
document.all("tab" + id, index).className = "tab";
for (var i=1; i

td.code {
padding:0,10,0,10;
border-style:solid;
border-width:1;
border-bottom:0;
border-top:0;
border-right:0;
border-color:cccccc;
background-color:ffffee
}
td.tab {
text-align:center;
font:8pt verdana;
width:15%;
padding:3,3,3,3;
border-style:solid;
border-width:1;
border-right:0;
border-color:black;
background-color:eeeeee;
cursor:hand
}
td.backtab {
text-align:center;
font: 8pt verdana;
width:15%;
padding:3,3,3,3;
border-style:solid;
border-width:1;
border-right:0;
border-color:black;
background-color:cccccc;
cursor:hand
}
td.space {
width:70%;
font: 8pt verdana;
padding:0,0,0,0;
border-style:solid;
border-bottom:0;
border-right:0;
border-width:1;
border-color:cccccc;
border-left-color:black;
background-color:white
}

// Infer the DataSet schema from the XML data and load the XML Data
datadoc.DataSet.ReadXml(new StreamReader("books.xml"), XmlReadMode.InferSchema);

' Infer the DataSet schema from the XML data and load the XML Data
datadoc.DataSet.ReadXml(new StreamReader("books.xml"), XmlReadMode.InferSchema)

C# VB
如在如何使用 XML 加载数据集中一样,此示例也使用了 DisplayTables 方法来显示数据集的结构和内容。下列输出显示当 DisplayTables 方法使用从 books.xml 文件推导出的架构时所生成的表名、列名和行内容。

Creating an XmlDataDocument ...
Content of Tables ...
TableName = book
---------
Columns ...
title                 book_Id               price                 genre                 publicationdate       ISBN
Number of rows = 3
Rows ...
The Autobiography of Benjamin Franklin 0                     8.99                  autobiography         1981                  1-861003-11-0
The Confidence Man    1                     11.99                 novel                 1967                  0-201-63361-2
The Gorgias           2                     9.99                  philosophy            1991                  1-861001-57-6
TableName = author
---------
Columns ...
first-name            last-name             book_Id
Number of rows = 3
Rows ...
Benjamin              Franklin              0
Herman                Melville              1
Sidas                 Plato                 2


摘要

推理是一种机制,通过它使得 XML 数据的结构成为关系架构的基础。
数据集的 ReadXml 方法使用 StreamReader 中所提供的 XML 文件生成关系映射。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐