Project

General

Profile

« Previous | Next » 

Revision 324

Added by Matt Jones over 24 years ago

removed old xmldbms source tree because it is no longer being used as a reference

View differences:

xmldbms/readme.html
1
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"
2
            "http://www.w3.org/TR/REC-html40/loose.dtd">
3
<HTML>
4
<HEAD>
5
   <TITLE>XML-DBMS, Version 1.0</TITLE>
6
   <META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
7
</HEAD>
8
<BODY>
9

  
10
<CENTER><H1>XML-DBMS, Version 1.0</H1>
11
<H2>Java Packages for Transferring Data between<BR />XML Documents and Relational Databases</H2>
12

  
13
<P><A HREF="http://www.informatik.tu-darmstadt.de/DVS1/staff/bourret/bourret.htm">Ronald Bourret</A><BR />
14
Technical University of Darmstadt</P></CENTER>
15

  
16
<H2>Contents</H2>
17

  
18
<P>
19
<A HREF="#Overview"/>1.0 Overview</A><BR />
20
<A HREF="#ObjectView"/>2.0 An Object View of an XML Document</A><BR />
21
<A HREF="#Maps"/>3.0 Map Objects, Map Factories, and the XML-DBMS Mapping Language</A><BR />
22
&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#Factories"/>3.1 Map Factories</A><BR />
23
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#MapFactory_MapDocument"/>3.1.1 MapFactory_MapDocument</A><BR />
24
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<a href="#MapFactory_DTD"/>3.1.2 MapFactory_DTD</A><BR />
25
&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#Lang"/>3.2 The XML-DBMS Mapping Language</A><BR />
26
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#LangSample"/>3.2.1 Sample Documents and Tables</A><BR />
27
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#LangClass"/>3.2.2 Mapping Classes (Element Types) to Tables</A><BR />
28
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#LangProp"/>3.2.3 Mapping Properties (Attributes and Element Types) to Columns</A><BR />
29
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#LangRel"/>3.2.4 Mapping Inter-Class Relationships (Element Hierarchy)</A><BR />
30
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#LangElim"/>3.2.5 Eliminating Unwanted Root Elements</A><BR />
31
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#LangMixed"/>3.2.6 Mapping Mixed Content</A><BR />
32
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#LangNS"/>3.2.7 Using Namespaces</A><BR />
33
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#Nulls"/>3.2.8 Handling Null Values</A><BR />
34
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#DateTime"/>3.2.9 Date, Time, and Timestamp Formats</A><BR />
35
<A HREF="#ToDBMS">4.0 Transferring Data to the Database</A><BR />
36
<A HREF="#ToXML">5.0 Transferring Data to an XML Document</A><BR />
37
<A HREF="#Supported">6.0 Supported Parsers and DOM Implementations</A><BR />
38
&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#Namespaces">6.1 Namespace Support</A><BR />
39
&nbsp;&nbsp;&nbsp;&nbsp;<A HREF="#DocumentFactories">6.2 Document Factories</A><BR />
40
<A HREF="#NotForUse">7.0 Classes Not for General Use</A><BR />
41
<A HREF="#Install">8.0 Downloading and Installing XML-DBMS</A><BR />
42
<A HREF="#Install">9.0 Samples</A><BR />
43
&nbsp;&nbsp;&nbsp;<a href="#TransferSample"/>9.1 Transfer</a><br />
44
&nbsp;&nbsp;&nbsp;<a href="#GenerateMapSample"/>9.2 GenerateMap</a><br />
45
&nbsp;&nbsp;&nbsp;<a href="#ConvertSchemaSample"/>9.3 ConvertSchema</a><br />
46
<A HREF="#Tips"/>10.0 Tips and Tricks</A><br />
47
<A HREF="#License">11.0 Licensing and Support</A><BR />
48
</P>
49

  
50
<H2><A NAME="Overview"/>1.0 Overview</H2>
51

  
52
<P>XML-DBMS is a set of Java packages for transferring data between XML documents and relational databases. Programmers use these packages to build systems that transfer data; a sample application can be run from the command line to transfer data between a database and an XML file.</P>
53

  
54
<P>XML-DBMS preserves the hierarchical structure of an XML document, as well as the data (character data and attribute values) in that document. If requested, it also preserves the order in which the children at a given level in the hierarchy appear. (For many data-centric applications, such order is not important and the code runs faster without it.)</P>
55

  
56
<P>Because XML-DBMS seeks to transfer data, not documents, it does not preserve document type declarations, nor does it preserve physical structure such as entity use, CDATA sections, or document encodings. In particular, it does not attempt to implement a document management system on top of a relational database.</P>
57

  
58
<p>For a general discussion of XML and databases, see <a href="http://www.informatik.tu-darmstadt.de/DVS1/staff/bourret/xml/XMLAndDatabases.htm">XML and Databases</a>.</p>
59

  
60
<H2><A NAME="ObjectView"/>2.0 An Object View of an XML Document</H2>
61

  
62
<P>XML-DBMS views an XML document as a tree of objects and then uses an object-relational mapping to map these objects to a relational database. The tree of objects is not, as one might initially guess, the Document Object Model (DOM). The reason for this is that the DOM models the document itself and not the data in the document.</P>
63

  
64
<P>Instead, the tree is constructed by viewing element types as classes, and attributes and PCDATA as properties of those classes. Subordinate element types are viewed as subordinate classes in the tree; that is, an interclass relationship exists between the parent and child classes.</P>
65

  
66
<P>The view of element types as classes is not absolute: element types can also be viewed as properties of their parent element type-as-class. This is most useful when an element type contains only PCDATA. However, it is useful in other cases as well. For example, consider an element type that contains a description written in XHTML. Although this description has subelements such as &lt;B&gt; and &lt;P&gt;, these subelements cannot be meaningfully interpreted on their own and it makes more sense to view the contents of the element type as a single value (property) rather than a class.</P>
67

  
68
<p>For example, in the following XML document, the SalesOrder and Customer element types might be viewed as classes and the OrderDate and Description element types as properties:</p>
69

  
70
<PRE>
71
   &lt;Orders&gt;
72
      &lt;SalesOrder SONumber="12345"&gt;
73
         &lt;Customer CustNumber="543"&gt;
74
            &lt;CustName&gt;ABC Industries&lt;/CustName&gt;
75
            &lt;Street&gt;123 Main St.&lt;/Street&gt;
76
            &lt;City&gt;Chicago&lt;/City&gt;
77
            &lt;State&gt;IL&lt;/State&gt;
78
            &lt;PostCode&gt;60609&lt;/PostCode&gt;
79
         &lt;/Customer&gt;
80
         &lt;OrderDate&gt;981215&lt;/OrderDate&gt;
81
         &lt;Line LineNumber="1"&gt;
82
            &lt;Part PartNumber="123"&gt;
83
               &lt;Description&gt;
84
                  &lt;P&gt;&lt;B&gt;Turkey wrench:&lt;/B&gt;&lt;BR /&gt;
85
                  Stainless steel, one-piece construction,
86
                  lifetime guarantee.&lt;/P&gt;
87
               &lt;/Description&gt;
88
               &lt;Price&gt;9.95&lt;/Price&gt;
89
            &lt;/Part&gt;
90
            &lt;Quantity&gt;10&lt;/Quantity&gt;
91
         &lt;/Line&gt;
92
         &lt;Line LineNumber="2"&gt;
93
            &lt;Part PartNumber="456"&gt;
94
               &lt;Description&gt;
95
                  &lt;P&gt;&lt;B&gt;Stuffing separator:&lt;B&gt;&lt;BR /&gt;
96
                  Aluminum, one-year guarantee.&lt;/P&gt;
97
               &lt;/Description&gt;
98
               &lt;Price&gt;13.27&lt;/Price&gt;
99
            &lt;/Part&gt;
100
            &lt;Quantity&gt;5&lt;/Quantity&gt;
101
         &lt;/Line&gt;
102
      &lt;/SalesOrder&gt;
103
   &lt;/Orders&gt;
104
</PRE>
105

  
106
<P>Exactly how element types, attributes, and PCDATA are viewed is left to the user, who specifies this information, as well now to map the object view to the database, in a Map object.</P>
107

  
108
<H2><A NAME="Maps"/>3.0 Map Objects, Map Factories, and the XML-DBMS Mapping Language</H2>
109

  
110
<P>A Map object declares the object view of the element types, attributes, and PCDATA in an XML document and how this view is mapped to the database. Map objects are opaque. That is, the programmer constructs a Map object with a map factory and passes it to the data transfer classes without calling any of its methods. For example, the following code calls a user-defined function to create a Map from a map document and passes it to the class that transfers data from an XML document to the database:</P>
111

  
112
<PRE>
113
   // Use a user-defined function that calls a map
114
   // factory to create a map. (See section 3.1.)
115
   map = createMap("sales.map", conn1);
116

  
117
   // Set the Map on the DOMToDBMS object.
118
   domToDBMS.setMap(map);
119
</PRE>
120

  
121
<P>The Map can also be set on the constructor.</P>
122

  
123
<P>Note that a Map object can be used multiple times. For example, suppose that a program expects to store four different types of XML documents in the database. It can create the Maps for these documents at start-up, then, as it receives documents to process, pass the appropriate Map to the DOMToDBMS object.</P>
124

  
125
<P><b>Disclaimer:</b>I haven't learned how Java multi-threading works, so the following may not be an issue.</p>
126

  
127
<p>Assuming it is possible for multiple threads to share the same object, multiple threads should not share the same Map. The reason for this is that a Map contains a reference to a Connection object and the data transfer classes (DBMSToDOM and DOMToDBMS) commit transactions on this object. Since Connection.commit() commits all statements open on a given Connection, a commit executed in one data transfer object will commit statements being used by all other data transfer objects sharing the same Map/Connection. This is unlikely to be the desired behavior.</P>
128

  
129
<H3><A NAME="Factories"/>3.1 Map Factories</H3>
130

  
131
<P>Currently, XML-DBMS has a two map factories: one to create Map objects from map documents and one to create Map objects from DTDs and schema documents.
132

  
133
<h4><a name="MapFactory_MapDocument"/>3.1.1 MapFactory_MapDocument</h4>
134

  
135
<p>The MapFactory_MapDocument class creates Map objects from map documents. It is the most commonly used map factory. For example, the following code creates a Map object from the sales.map map document:</P>
136

  
137
<PRE>
138
   // Instantiate a new map factory from a database connection
139
   // and a SAX parser.
140
   factory = new MapFactory_MapDocument(conn, parser);
141

  
142
   // Create a Map from sales.map.
143
   map = factory.createMap(new InputSource(new FileReader("sales.map")));
144
</PRE>
145

  
146
<h4><a name="MapFactory_DTD"/>3.1.2 MapFactory_DTD</h4>
147

  
148
<p>The MapFactory_DTD class creates Map objects from DTDs and XML schema documents. This factory is designed primarily for use as a tool to help build mapping documents. For example, the following code creates a Map object from document.dtd and then serialized that Map object to a file.</p>
149

  
150
<pre>
151
   // Instantiate a new map factory and create a map.
152
   factory = new MapFactory_DTD();
153
   src = new InputSource("file://c:/java/de/tudarmstadt/ito/xmldbms/samples/document.dtd");
154
   map = factory.createMapFromDTD(src, MapFactory_DTD.DTD_EXTERNAL, true, null);<br />
155

  
156
   // Open a FileOutputStream and serialize the Map to that stream.
157
   mapFile = new FileOutputStream("c:\java\de\tudarmstadt\ito\xmldbms\samples\document.map");
158
   map.serialize(mapFile);
159
   mapFile.close();
160
</pre>
161

  
162
<p>Maps created by MapFactory_DTD cannot be used to transfer data until the Map.setConnection method has been called to specify a JDBC Connection.</p>
163

  
164
<p>MapFactory_DTD supports DTDs in two forms: either an external subset -- that is, a stand-alone DTD file -- or an XML document containing an internal subset, reference to an external subset, or both. Currently, the only schema language it supports is <a href="http://www.w3.org/TR/NOTE-ddml">DDML (Data Definition Markup Language)</a>. If you need to use another schema language, such as <a href="http://www.w3.org/TR/NOTE-dcd">DCD (Document Content Description for XML)</a>, <a href="http://www.w3.org/TR/NOTE-SOX/">SOX (Schema for Object-Oriented XML)</a>, the <a href="http://www.w3.org/TR/xmlschema-1/">W3C's XML Schema language</a>, or <a href="http://www.ltg.ed.ac.uk/~ht/XMLData-Reduced.htm">XML-Data Reduced</a>, you will need to write a conversion module similar to de.tudarmstadt.ito.schemas.converters.DDMLToDTD.</p>
165

  
166
<H3><A NAME="Lang"/>3.2 The XML-DBMS Mapping Language</H3>
167

  
168
<P>The XML-DBMS mapping language is a simple, XML-based language that describes both how to construct an object view for an XML document and how to map this view to a relational schema. We will introduce the main parts of the language in a series of examples. For complete information, see the <A HREF="xmldbms.dtd">XML-DBMS DTD</A>.</P>
169

  
170
<H4><A NAME="LangSample"/>3.2.1 Sample Documents and Tables</H4>
171

  
172
<P>The examples use the sales language shown in <a href="#ObjectView">section 2.0</a>, the document language shown in figure 1, and the tables shown in figures 2 and 3.</p>
173

  
174
<hr />
175

  
176
<P><B>&nbsp;&nbsp;&nbsp;Figure 1: Sample document in Document language:</B></P>
177

  
178
<PRE>
179
   &lt;!DOCTYPE Product SYSTEM "document.dtd"&gt;
180

  
181
   &lt;Product&gt;
182

  
183
   &lt;Name&gt;XML-DBMS&lt;/Name&gt;
184

  
185
   &lt;Developer&gt;Ronald Bourret, Technical University of Darmstadt&lt;/Developer&gt;
186

  
187
   &lt;Summary&gt;Java packages for transferring data between
188
   XML documents and relational databases&lt;/Summary&gt;
189

  
190
   &lt;Description&gt;
191

  
192
   &lt;Para&gt;XML-DBMS is a set of Java packages for transferring data between
193
   XML documents and relational databases. It views the XML document as a tree
194
   of objects in which element types are generally viewed as classes and
195
   attributes and PCDATA as properties of those classes. It then uses an object-
196
   relational mapping to map these objects to the database. An XML-based mapping
197
   language is used to define the view and map it to the database.&lt;/Para&gt;
198
   
199
   &lt;Para&gt;You can:&lt;/Para&gt;
200
   
201
   &lt;List&gt;
202
   &lt;Item&gt;&lt;Link URL="readme.html"&gt;Read more about XML-DBMS&lt;/Link&gt;&lt;/Item&gt;
203
   &lt;Item&gt;&lt;Link URL="XMLAndDatabases.htm"&gt;Read more about databases and XML&lt;/Link&gt;&lt;/Item&gt;
204
   &lt;Item&gt;&lt;Link URL="xmldbms.dtd"&gt;View the mapping language DTD&lt;/Link&gt;&lt;/Item&gt;
205
   &lt;Item&gt;&lt;Link URL="xmldbms.zip"&gt;Download XML-DBMS&lt;/Link&gt;&lt;/Item&gt;
206
   &lt;/List&gt;
207
   
208
   &lt;Para&gt;XML-DBMS, along with its source code, is freely available for use
209
   in both commercial and non-commercial settings.&lt;/Para&gt;
210
   
211
   &lt;/Description&gt;
212
   
213
</PRE>
214

  
215
<hr />
216

  
217
<P><B>&nbsp;&nbsp;&nbsp;Figure 2: Sales data tables:</B></P>
218

  
219
<TABLE>
220
  <TR>
221
   <TH>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TH>
222
   <TH ALIGN=LEFT>Sales</TH>
223
   <TH>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TH>
224
   <TH ALIGN=LEFT>Lines</TH>
225
   <TH>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TH>
226
   <TH ALIGN=LEFT>Customers</TH>
227
   <TH>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TH>
228
   <TH ALIGN=LEFT>Parts</TH>
229
  </TR>
230
  <TR>
231
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
232
   <TD>Number</TD>
233
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
234
   <TD>SONumber</TD>
235
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
236
   <TD>Number</TD>
237
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
238
   <TD>Number</TD>
239
  </TR>
240
  <TR>
241
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
242
   <TD>CustNumber</TD>
243
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
244
   <TD>Number</TD>
245
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
246
   <TD>Name</TD>
247
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
248
   <TD>Description</TD>
249
  </TR>
250
  <TR>
251
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
252
   <TD>Date</TD>
253
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
254
   <TD>Part</TD>
255
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
256
   <TD>Street</TD>
257
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
258
   <TD>Price</TD>
259
  </TR>
260
  <TR>
261
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
262
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
263
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
264
   <TD>Quantity</TD>
265
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
266
   <TD>City</TD>
267
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
268
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
269
  </TR>
270
  <TR>
271
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
272
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
273
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
274
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
275
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
276
   <TD>State</TD>
277
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
278
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
279
  </TR>
280
  <TR>
281
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
282
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
283
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
284
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
285
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
286
   <TD>Country</TD>
287
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
288
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
289
  </TR>
290
  <TR>
291
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
292
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
293
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
294
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
295
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
296
   <TD>PostalCode</TD>
297
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
298
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
299
  </TR>
300
</TABLE>
301

  
302
<hr />
303

  
304
<P><B>&nbsp;&nbsp;&nbsp;Figure 3: Document data tables:</B></P>
305

  
306
<TABLE>
307
  <TR>
308
   <TH>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TH>
309
   <TH ALIGN=LEFT>Product</TH>
310
   <TH>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TH>
311
   <TH ALIGN=LEFT>Description</TH>
312
   <TH>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TH>
313
   <TH ALIGN=LEFT>Para</TH>
314
   <TH>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TH>
315
   <TH ALIGN=LEFT>ParaPCDATA</TH>
316
  </TR>
317
  <TR>
318
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
319
   <TD>ProductID</TD>
320
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
321
   <TD>ProductID</TD>
322
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
323
   <TD>DescriptionID</TD>
324
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
325
   <TD>ParaID</TD>
326
  </TR>
327
  <TR>
328
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
329
   <TD>ProductOrder</TD>
330
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
331
   <TD>DescriptionID</TD>
332
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
333
   <TD>ParaID</TD>
334
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
335
   <TD>ParaPCDATA</TD>
336
  </TR>
337
  <TR>
338
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
339
   <TD>Name</TD>
340
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
341
   <TD>DescriptionOrder</TD>
342
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
343
   <TD>ParaOrder</TD>
344
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
345
   <TD>ParaPCDATAOrder</TD>
346
  </TR>
347
  <TR>
348
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
349
   <TD>NameOrder</TD>
350
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
351
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
352
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
353
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
354
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
355
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
356
  </TR>
357
  <TR>
358
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
359
   <TD>Developer</TD>
360
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
361
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
362
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
363
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
364
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
365
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
366
  </TR>
367
  <TR>
368
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
369
   <TD>DeveloperOrder</TD>
370
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
371
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
372
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
373
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
374
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
375
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
376
  </TR>
377
  <TR>
378
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
379
   <TD>Summary</TD>
380
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
381
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
382
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
383
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
384
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
385
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
386
  </TR>
387
  <TR>
388
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
389
   <TD>SummaryOrder</TD>
390
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
391
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
392
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
393
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
394
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
395
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
396
  </TR>
397
  <TR>
398
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
399
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
400
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
401
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
402
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
403
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
404
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
405
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
406
  </TR>
407
  <TR>
408
   <TH>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TH>
409
   <TH ALIGN=LEFT>List</TH>
410
   <TH>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TH>
411
   <TH ALIGN=LEFT>Item</TH>
412
   <TH>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TH>
413
   <TH ALIGN=LEFT>ItemPCDATA</TH>
414
   <TH>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TH>
415
   <TH ALIGN=LEFT>Link</TH>
416
  </TR>
417
  <TR>
418
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
419
   <TD>DescriptionID</TD>
420
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
421
   <TD>ListID</TD>
422
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
423
   <TD>ItemID</TD>
424
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
425
   <TD>ParaID</TD>
426
  </TR>
427
  <TR>
428
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
429
   <TD>ListID</TD>
430
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
431
   <TD>ItemID</TD>
432
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
433
   <TD>ItemPCDATA</TD>
434
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
435
   <TD>ItemID</TD>
436
  </TR>
437
  <TR>
438
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
439
   <TD>ListOrder</TD>
440
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
441
   <TD>ItemOrder</TD>
442
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
443
   <TD>ItemPCDATAOrder</TD>
444
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
445
   <TD>LinkOrder</TD>
446
  </TR>
447
  <TR>
448
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
449
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
450
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
451
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
452
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
453
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
454
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
455
   <TD>URL</TD>
456
  </TR>
457
  <TR>
458
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
459
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
460
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
461
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
462
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
463
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
464
   <TD>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</TD>
465
   <TD>LinkPCDATA</TD>
466
  </TR>
467
</TABLE>
468

  
469
<hr />
470

  
471
<H4><A NAME="LangClass"/>3.2.2 Mapping Classes (Element Types) to Tables</H4>
472

  
473
<P>Element types with element content are usually viewed as classes and mapped to a table. For example, the following declares the SalesOrder element type to be a class and maps it to the Sales table:</P>
474

  
475
<PRE>
476
   &lt;ClassMap&gt;
477
      &lt;ElementType Name="SalesOrder"/&gt;
478
      &lt;ToClassTable&gt;
479
         &lt;Table Name="Sales"/&gt;
480
      &lt;/ToClassTable&gt;
481
      ...property maps...
482
      ...related class maps...
483
      ...pass-through maps...
484
   &lt;/ClassMap&gt;
485
</PRE>
486

  
487
<P>The ClassMap element contains all of the information needed to map a single class (element type), including the table to which the class is mapped, the maps for each property in the class, a list of related classes, and a list of passed-through child classes.</P>
488

  
489
<P>The ElementType element identifies the element type (class) being mapped and the ToClassTable element gives the name of the table to which the class is mapped.</P>
490

  
491
<H4><A NAME="LangProp"/>3.2.3 Mapping Properties (Attributes and Element Types) to Columns</H4>
492

  
493
<P>Single-valued attributes and element types with PCDATA-only content are usually viewed as properties and mapped to columns. For example, the following declares the SONumber attribute and the OrderDate element type (when SalesOrder is its parent) to be properties and maps them to the Number and Date columns, respectively. These maps are nested inside the class map for SalesOrder.</P>
494

  
495
<PRE>
496
   &lt;PropertyMap&gt;
497
      &lt;Attribute Name="SONumber"/&gt;
498
      &lt;ToColumn&gt;
499
         &lt;Column Name="Number"/&gt;
500
      &lt;/ToColumn&gt;
501
   &lt;/PropertyMap&gt;
502

  
503
   &lt;PropertyMap&gt;
504
      &lt;ElementType Name="OrderDate"/&gt;
505
      &lt;ToColumn&gt;
506
         &lt;Column Name="Date"/&gt;
507
      &lt;/ToColumn&gt;
508
   &lt;/PropertyMap&gt;
509
</PRE>
510

  
511
<P>The Attribute and ElementType elements identify the properties being mapped and the ToColumn elements state that they are being mapped to columns. These columns are understood to be in the table to which the class (SalesOrder) is mapped.</P>
512

  
513
<H4><A NAME="LangRel"/>3.2.4 Mapping Inter-Class Relationships (Element Hierarchy)</H4>
514

  
515
<P>When a child element type is viewed as a class, its relationship with its parent element type must be stated in the map of the parent class. For example, the following declares that Line is related to the SalesOrder class. This map is nested inside the class map for SalesOrder; the actual mapping of the Line class is separate.</P>
516

  
517
<PRE>
518
   &lt;RelatedClass KeyInParentTable="Candidate"&gt;
519
      &lt;ElementType Name="Line"/&gt;
520
      &lt;CandidateKey Generate="No"&gt;
521
         &lt;Column Name="Number"/&gt;
522
      &lt;CandidateKey/&gt;
523
      &lt;ForeignKey&gt;
524
         &lt;Column Name="SONumber"/&gt;
525
      &lt;/ForeignKey&gt;
526
      &lt;OrderColumn Name="Number" Generate="No"/&gt;
527
   &lt;/RelatedClass&gt;
528
</PRE>
529

  
530
<P>The ElementType element gives the name of the related class and the KeyInParentTable attribute states that the candidate key used to join the tables is in the parent (Sales) table. CandidateKey and ForeignKey give the columns in these keys, which must match in number and type. The Generate attribute of CandidateKey tells the system whether to generate the key. This allows us to preserve keys that have business meaning and generate object identifiers when no such keys exist. In this case, we do not generate the key because we have mapped the SONumber attribute of the SalesOrder element type to the candidate key column (Sales.Number).</P>
531

  
532
<P>The (optional) OrderColumn element gives the name of the column that contains information about the order in which Line elements appear in the SalesOrder element. Because this column must appear in the table on the "many" side of the relationship, Number refers to the Lines.Number column, not the Sales.Number column. The Generate attribute of the OrderColumn element tells the system whether to generate the order value. In this case, we do not generate the order value because we will separately map the LineNumber attribute of the Line element type to the order column (Lines.Number).</P>
533

  
534
<H4><A NAME="LangElim"/>3.2.5 Eliminating Unwanted Root Elements</H4>
535

  
536
<P>Root elements sometimes exist only because XML requires a single root element. For example, in our sales order language, we would like to store multiple sales orders in a single document. To do this, we need the Orders element to encapsulate multiple SalesOrder elements. However, there is no structure in the database corresponding to the Orders element and we would like to eliminate it. For example, the following states that the Orders element type is to be ignored.</P>
537

  
538
<PRE>
539
   &lt;IgnoreRoot&gt;
540
      &lt;ElementType Name="Orders"/&gt;
541
      &lt;PseudoRoot&gt;
542
         &lt;ElementType Name="SalesOrder"/&gt;
543
         &lt;CandidateKey Generate="No"&gt;
544
            &lt;Column Name="Number"/&gt;
545
         &lt;/CandidateKey&gt;
546
      &lt;/PseudoRoot&gt;
547
   &lt;/IgnoreRoot&gt;
548
</PRE>
549

  
550
<P>The first ElementType element gives the element type to be ignored. The PseudoRoot element introduces an element type (SalesOrder) to serve as a root in its place; there can be multiple pseudo-roots. The (optional) CandidateKey element gives the key to be used when retrieving data from the database; not shown is an option OrderColumn element that gives the order in which the SalesOrder elements are to be retrieved.</P>
551

  
552
<p>Ignored root elements are reconstructed when retrieving data from the database.</p>
553

  
554
<H4><A NAME="LangMixed"/>3.2.6 Mapping Mixed Content</H4>
555

  
556
<P>Mixed content consists of both PCDATA and elements, such as in our document language. The order in which the PCDATA and elements appear is usually important, so we usually need to keep order information for the PCDATA as well as each element. For example, the following maps the Name element type to the Name column in the Product table and stores system-generated order information in the NameOrder column; this map is nested inside the class map for the Product element type.</P>
557

  
558
<PRE>
559
   &lt;PropertyMap&gt;
560
      &lt;ElementType Name="Name"/&gt;
561
      &lt;ToColumn&gt;
562
         &lt;Column Name="Name"/&gt;
563
      &lt;/ToColumn&gt;
564
      &lt;OrderColumn Name="NameOrder" Generate="Yes"/&gt;
565
   &lt;/PropertyMap&gt;
566
</PRE>
567

  
568
<P>Because PCDATA can occur multiple times in mixed content, it is usually mapped to a separate table. For example, the following maps the PCDATA from the Para element type to the ParaPCDATA table; this map is nested inside the class map for the Para element type.</P>
569

  
570
<PRE>
571
   &lt;PropertyMap&gt;
572
      &lt;PCDATA/&gt;
573
      &lt;ToPropertyTable KeyInParentTable="Candidate"&gt;
574
         &lt;Table Name="ParaPCDATA"/&gt;
575
         &lt;CandidateKey Generate="Yes"&gt;
576
            &lt;Column Name="ParaID"/&gt;
577
         &lt;/CandidateKey&gt;
578
         &lt;ForeignKey&gt;
579
            &lt;Column Name="ParaID"/&gt;
580
         &lt;/ForeignKey&gt;
581
         &lt;Column Name="ParaPCDATA"/&gt;
582
         &lt;OrderColumn Name="ParaPCDATAOrder" Generate="Yes"/&gt;
583
      &lt;/ToPropertyTable&gt;
584
   &lt;/PropertyMap&gt;
585
</PRE>
586

  
587
<P>The ToPropertyTable element states that the table contains only property values, not a class. In addition to giving the candidate and foreign keys needed to retrieve PCDATA values from the table, we give the names of the columns (ParaPCDATA and ParaPCDATAOrder) in which the PCDATA and order information are stored. Notice that we ask the system to generate both the candidate key (ParaID) and the order information; this is because the document does not contain this information.</P>
588

  
589
<p>As you may have noticed, the document language requires more tables and more columns per property than the sales order language. This is because the document language is an example of a <i>document-centric</i> language, while the sales language is an example of a <i>data-centric</i> language.</p>
590

  
591
<p>Document-centric languages are used to create documents for human consumption, such as books, email, and advertisements. They are characterized by less predictable structures, coarser-grained data, and large amounts of mixed content and the order in which sibling elements and PCDATA occurs is usually significant. Because order is usually signficant and element types-as-properties and PCDATA generally can occur multiple times in their parent (thus requiring storage in separate tables), document-centric languages require a more complex structure in the database.</P>
592

  
593
<p>Data-centric languages tend to describe discrete pieces of data and are typically used to transfer data between applications and data stores. They are characterized by fairly regular structure, fine-grained data (the smallest independent unit of data is usually at the attribute or PCDATA-only element level), and little or no mixed content. The order in which sibling elements and PCDATA occurs is usually not significant. Because of their regular structure and the unimportance of order, data-centric languages require a less complex structure in the database.</P>
594

  
595
</p>Although XML-DBMS and relational databases can be used to store documents written in document-centric languages, they are better suited to storing the regular structure encountered in documents written in data-centric languages.</p>
596

  
597
<H4><A NAME="LangNS"/>3.2.7 Using Namespaces</H4>
598

  
599
<P>Namespaces are supported through Namespace elements, which declare the prefixes and URIs used in the Name attributes of ElementType and Attribute elements. (Note that these prefixes are separate from those declared with xmlns attributes.) For example, suppose the sales order language has a namespace URI of http://ito.tu-darmstadt.de/xmldbms/sales. The map document might contain the following Namespace element, which states that the sales prefix is used in the map document to identify element types and attributes from this namespace.</P>
600

  
601
<PRE>
602
   &lt;Namespace Prefix="sales" URI="http://ito.tu-darmstadt.de/xmldbms/sales"/&gt;
603
</PRE>
604

  
605
<P>Thus, when mapping the SalesOrder element type, the following reference is used:</P>
606

  
607
<PRE>
608
   &lt;ElementType Name="sales:SalesOrder"/&gt;
609
</PRE>
610

  
611
<P>As with namespaces in XML documents, unprefixed attribute names referenced in the Name attribute of the Attribute element type do not belong to any XML namespace. (For those of you who are confused by this statement, remember that such attribute names must be unique within their element type; this is a requirement imposed by the XML specification and has nothing to do with XML namespaces.) For example, in the following class map, the SONumber attribute is assumed to belong to the SalesOrder element type; it does not belong to any XML namespace.</P>
612

  
613
<PRE>
614
   &lt;ClassMap&gt;
615
      &lt;ElementType Name="sales:SalesOrder"/&gt;
616
      &lt;ToClassTable&gt;
617
         &lt;Table Name="Sales"/&gt;
618
      &lt;/ToClassTable&gt;
619
      &lt;PropertyMap&gt;
620
         &lt;Attribute Name="SONumber"/&gt;
621
         &lt;ToColumn&gt;
622
            &lt;Column Name="Number"/&gt;
623
         &lt;/ToColumn&gt;
624
      &lt;/PropertyMap&gt;
625
   &lt;/ClassMap&gt;
626
</PRE>
627

  
628
<P>Prefixes used in the map document do not need to match those used in instance documents. All that is important is that the namespace URIs are the same. Currently, Namespace elements do not support empty prefixes; that is, you cannot declare a namespace URI that will be associated with unprefixed element type and attribute names in the map document.</P>
629

  
630
<P>Whether a document using namespaces can actually be processed depends on the DOM implementation being used. For more information, see section 6.1, "<A HREF="#Namespaces">Namespace Support</A>".</P>
631

  
632
<H4><A NAME="Nulls"/>3.2.8 Handling Null Values</H4>
633

  
634
<p>A null value is a value that simply isn't there. This is very different from a value of 0 (for numbers) or zero length (for a string). For example, suppose you have data collected from a weather station. If the thermometer isn't working, a null value is stored in the database rather than a 0, which would mean something different altogether.</p>
635

  
636
<p>XML also supports the concept of null data through optional element types and attributes. If the value of an optional element type or attribute is null, it simply isn't included in the document. As with databases, empty elements or attributes containing zero length strings are not null: their value is a zero-length string.</p>
637

  
638
<p>In spite of this definition of null values, it is quite likely that XML documents will use empty (zero-length) strings to represent null values. Because of this, the EmptyStringIsNull element can be used to state how empty strings are treated. If it is present, empty strings are treated in the same way as null values. If it is absent, empty strings are treated as strings. For example, the following states that empty strings should be treated as nulls.
639

  
640
<pre>
641
   &lt;EmptyStringIsNull/&gt;
642
</pre>
643

  
644
<p>The EmptyStringIsNull element is nested inside the Options element. Note that it applies only to element types and attributes mapped as propertys. An empty element-as-class with no attributes results in a row of all NULLs in the database.</p>
645

  
646
<H4><A NAME="DateTime"/>3.2.9 Date, Time, and Timestamp Formats</H4>
647

  
648
<p>Because XML documents are international, it is likely that you will encounter a variety of date, time, and timestamp formats. You can specify the formats to use with the DateTimeFormats element, which contains an optional Locale element and a Patterns element that specifies the actual formatting patterns to use. For example, the following specifies that dates use the "dd.MM.yy" format (e.g. 29.10.58), times use the "HH:mm" format (e.g. 18:37), and timestamps use the "MMM d, yyyy h:mm a" (e.g. February 9, 1962 6:35 AM).
649

  
650
<pre>
651
   &lt;DateTimeFormats&gt;
652
      &lt;Patterns Date="HH:mm" Time="HH:mm" Timestamp="MMM d, yyyy h:mm"/&gt;
653
   &lt;/DateTimeFormats&gt;
654
</pre>
655

  
656
<p>Like EmptyStringIsNull, the DateTimeFormats element is nested inside the Options element. The formats used are defined in the java.text.DateFormat and java.text.SimpleDateFormat classes.</p>
657

  
658
<H2><A NAME="ToDBMS"/>4.0 Transferring Data to the Database</H2>
659

  
660
<P>The DOMToDBMS class transfers data from a DOM tree to the database according to a given Map. For example, the following code transfers data from the sales_in.xml document to the database according to the Map object created from sales.map:</P>
661

  
662
<PRE>
663
   // Use a user-defined function to create a map.
664
   map = createMap("sales.map", conn1);
665

  
666
   // Use a user-defined function to create a DOM tree over sales_in.xml
667
   doc = openDocument("sales_in.xml");
668

  
669
   // Create a new DOMToDBMS object and store the data.
670
   domToDBMS = new DOMToDBMS(map);
671
   docInfo = domToDBMS.storeDocument(doc);
672
</PRE>
673

  
674
<P>Information about how to retrieve the data at a later point in time is returned in a DocumentInfo object, which is just a list of table names, key column names, key values, and order column names.</P>
675

  
676
<P>If DOMToDBMS needs to generate key values, as in our <A HREF="#LangMixed">document example</A>, the caller must provide an object that implements the KeyGenerator interface. DOMToDBMS calls a method this object to get unique key values; a default implementation of this object (KeyGeneratorImpl), which generates unique 4-byte integers, can be found in the de.tudarmstadt.ito.xmldbms.helpers package. For example:</P>
677

  
678
<PRE>
679
   // Use a user-defined function to create a map.
680
   Map map = createMap("document.map", conn1);
681

  
682
   // Use a user-defined function to create a DOM tree over document_in.xml
683
   doc = openDocument("document_in.xml");
684

  
685
   // Instantiate KeyGeneratorImpl and initialize it with a Connection.
686
   keyGenerator = new KeyGeneratorImpl();
687
   keyGenerator.initialize(conn2);
688

  
689
   // Create a new DOMToDBMS object and set the KeyGenerator.
690
   domToDBMS = new DOMToDBMS(map);
691
   domToDBMS.setKeyGenerator(keyGenerator);
692

  
693
   // Store the data.
694
   docInfo = domToDBMS.storeDocument(doc);
695
</PRE>
696

  
697
<P>The KeyGenerator can also be set on the constructor.</P>
698

  
699
<P>Note that the KeyGeneratorImpl object and the DOMToDBMS object use different connections to the same database. This is because each commits transactions at different times and using the same connection for both objects would lead to statements being committed prematurely.</P>
700

  
701
<H2><A NAME="ToXML"/>5.0 Transferring Data to an XML Document</H2>
702

  
703
<P>The DBMSToDOM class transfers data from the database to a DOM tree according to a given Map. For example, the following code transfers data for sales order number 123 from the Sales table to the sales_out.xml document according to the Map object created from sales.map:</P>
704

  
705
<PRE>
706
   // Use a user-defined function to create a map.
707
   map = createMap("sales.map", conn);
708

  
709
   // Create a new DBMSToDOM object.
710
   dbmsToDOM = new DBMSToDOM(map, new DF_Oracle());
711

  
712
   // Create a key and retrieve the data.
713
   key = {new Integer(123)};
714
   doc = dbmsToDOM.retrieveDocument("Sales", key);
715
</PRE>
716

  
717
<P>Note that the DBMSToDOM object is created with a DocumentFactory (DF_Oracle) that can create Documents for Oracle's implementation of the DOM. For more information, see section 6.2, "<A HREF="#DocumentFactories">Document Factories</A>".
718

  
719
<P>The DBMSToDOM class has four different retrieveDocument methods. In addition to the method shown above, there are methods that accept arrays of tables and keys, a DocumentInfo object, and a ResultSet object as arguments. In the latter case, the Map object must map an element type to the table named "Result Set".</P>
720

  
721
<P>If the data specified by the parameters of a retrieveDocument method contains more than one row, the Map object must specify an ignored root type. Otherwise, DBMSToDOM will attempt to add more than one root element to the document, resulting in a DOMException. (Note that this does not include rows of data retrieved from subordinate tables.)</P>
722

  
723
<H2><A NAME="Supported"/>6.0 Supported Parsers and DOM Implementations</H2>
724

  
725
<P>XML-DBMS is written in a parser and DOM-neutral fashion and should be able to use any parser that supports SAX and any Java implementation of the DOM. Unfortunately, there are no standard ways to support namespaces in the DOM, nor are there standard ways to create empty DOM documents. Thus, these capabilities are encapsulated in the NameQualifier and DocumentFactory interfaces in the de.tudarmstadt.ito.domutils package.</P>
726

  
727
<H3><A NAME="Namespaces"/>6.1 Namespace Support</H3>
728

  
729
<P>The DOM specification does not define how namespaces are supported. Thus, some DOM implementations have defined methods for retrieving various information about the namespace used by a given Node. We have encapsulated a subset of this information in the NameQualifier interface. This interface uses the following definitions:</P>
730

  
731
<DL>
732
  <DT>Local name</DT>
733
  <DD>The unprefixed name of a node.<DD>
734
  <DT>Prefixed name</DT>
735
  <DD>The prefixed name of a node. If there is no namespace URI, the prefixed name is the same as the local name.<DD>
736
  <DT>Qualified name</DT>
737
  <DD>The namespace URI, plus a caret (^), plus the local name. If there is no namespace URI, the qualified name is the same as the local name.</DD>
738
</DL>
739

  
740
<P>For example:</P>
741

  
742
<PRE>
743
   &lt;foo:element1 xmlns="http://foo">
744
   Local name: "element1"
745
   Prefixed name: "foo:element1"
746
   Qualified name: "http://foo^element1"
747

  
748
   &lt;element2>
749
   Local name: "element2"
750
   Prefixed name: "element2"
751
   Qualified name: "element2"
752
</PRE>
753

  
754
<P>To use namespaces, the DOM implementation must support namespaces and the Map object must declare the namespace URI (if any) of each mapped element type and attribute (see section 3.2.7, "<A HREF="#LangNS"/>Using Namespaces</A>"). If a DOM implementation does not support namespaces, then the element type and attribute names in the Map object must exactly match the names returned by the DOM's implementation Node.getNodeName(). Usually, this will be the prefixed name.</P>
755

  
756
<P>When transferring data from an XML document to the database, the caller must pass an object that implements the NameQualifier interface to the DOMToDBMS object. For example, the following code passes a NameQualifier for Oracle's DOM implementation:</P>
757

  
758
<PRE>
759
   domToDBMS.setNameQualifier(new NQ_Oracle());
760
</PRE>
761

  
762
<P>The NameQualifier may also be set in the constructor and no NameQualifier is needed if neither the XML document nor the Map uses namespaces. The de.tudarmstadt.ito.domutils package includes implementations of NameQualifier for DataChannel (Microsoft), IBM, Oracle, and Sun. As of this writing, Docuverse and OpenXML do not support namespaces. However, you should check whether a newer version of either implemenation does; implementing NameQualifier yourself is trivial.</P>
763

  
764
<P>When transferring data from the database to an XML document, the caller must choose how namespaces will be used. Currently, no DOM implementations support setting the namespace or prefix of an element or attribute. Thus, the caller can choose whether element and attribute names are prefixed according to the namespace prefixes in the Map or no prefixes are used at all.</P>
765

  
766
<P>Prefixing the element and attribute names in the returned DOM tree is useful if the DOM tree is to be serialized as XML. However, it will probably cause problems if the DOM tree is to be used directly. The reason for this is that the DOM implementation will not correctly recognize and return the unprefixed name, the namespace URI, or the qualified name. By default, prefixes are not used. The following code shows how to request that prefixes be used:</P>
767

  
768
<PRE>
769
   dbmsToDOM.usePrefixes(true);
770
</PRE>
771

  
772
<H3><A NAME="DocumentFactories"/>6.2 Document Factories</H3>
773

  
774
<P>Like namespace support, there is no standard way to create an empty DOM Document. Thus, we have encapsulated this functionality in the DocumentFactory interface. When transferring data from the database to an XML document, an object implementing this interface must be passed to the DBMSToDOM object. For example, the following code uses the DocumentFactory for Oracle:</P>
775

  
776
<PRE>
777
   dbmsToDOM.setDocumentFactory(new DF_Oracle());
778
</PRE>
779

  
780
<P>The DocumentFactory may also be set in the constructor. The de.tudarmstadt.ito.domutils package contains implementations of DocumentFactory for the DataChannel (Microsoft), Docuverse, IBM, OpenXML, Oracle, and Sun DOM implementations. Be sure to check that these implementations match the version of the implementation you are using. If not, you may need to implement DocumentFactory yourself; doing so is trivial.</P>
781

  
782
<H2><A NAME="NotForUse"/>7.0 Classes Not for General Use</H2>
783

  
784
<P>The de.tudarmstadt.ito.xmldbms package contains a number of public classes that are not for general use. That is, programmers using XML-DBMS do not need to instantiate or call methods on these classes. These classes are used to map XML document structures to database structures and are public so that they can be used by map factories, which are in a different package.</P>
785

  
786
<P>The not-for-general-use mapping classes are:</P>
787

  
788
<PRE>
789
   ClassMap
790
   Column
791
   ColumnMap
792
   LinkInfo
793
   MapOptions
794
   OrderInfo
795
   PropertyMap
796
   RelatedClassMap
797
   RootClassMap
798
   RootTableMap
799
   Table
800
   TableMap
801
</PRE>
802

  
803
<P>A special case is the Map class. For programmers using XML-DBMS, this is generally treated as an opaque object. That is, the programmer gets a Map object from a map factory and passes it to DOMToDBMS or DBMSToDOM. In addition, the Map object has public methods that some (but not all) XML-DBMS programmers use, such as methods to serialize the map to an OutputStream and to get CREATE TABLE statements. Although many variables in the Map class are public, programmers should never need to access them.</P>
804

  
805
<P>It is possible for programmers to directly create objects in the mapping classes, but it is strongly recommended that a map factory be used instead. Note that DOMToDBMS and DBMSToDOM largely assume that the objects in these classes have been created correctly, so using incorrectly constructed objects has unpredictable results. However, should a programmer be brave (foolish?) enough to construct these objects by hand, a slightly simplified hierarchy of them is as follows:</P>
806

  
807
<PRE>
808
   Map
809
      Table (array of)
810
      TableMap (array of)
811
      RootClassMap (hashtable of)
812
         ClassMap
813
            PropertyMap (hashtable of)
814
            RelatedClassMap (hashtable of)
815
               ClassMap...
816
               LinkInfo
817
               OrderInfo
818
         LinkInfo
819
         OrderInfo
820
      RootTableMap (hashtable of)
821
         TableMap
822
            Table
823
               Column (array of)
824
            ColumnMap (array of)
825
               Column
826
            TableMap... (array of)
827
</PRE>
828

  
829
<H2><A NAME="Install"/>8.0 Downloading and Installing XML-DBMS</H2>
830
<P>You can download the current version of XML-DBMS from <A HREF="http://www.informatik.tu-darmstadt.de/DVS1/staff/bourret/xmldbms/xmldbms.htm">here</A>.</P>
831

  
832
<P>To install, unzip the downloaded file and add xmldbms.jar to your CLASSPATH.</P>
833

  
834
<P>XML-DBMS has been used with JDK versions 1.1.8 and 1.2 and a number of different databases and JDBC drivers.</P>
835

  
836
<H2><A NAME="Samples"/>9.0 Samples</H2>
837

  
838
<P>XML-DBMS comes with three samples, Transfer, GenerateMap, and ConvertSchema, which can be found in the samples subdirectory.</p>
839

  
840
<h3><a name="TransferSample"/>9.1 Transfer</h3>
841
<i>Transfer</i> is a simple command-line application that transfers data between an XML file and the database according to a particular map document. It shows how to use the MapFactory_MapDocument, DOMToDBMS, DBMSToDOM, and Map classes.</P>
842

  
843
<P>When transferring data from an XML document to the database, use the command:</P>
844

  
845
<PRE>
846
   java Transfer -todbms &lt;map-file&gt; &lt;xml-file&gt;
847
</PRE>
848

  
849
<P>For example, to transfer data from the sample file document_in.xml to the database according the map document document.map, use the command:</P>
850

  
851
<PRE>
852
   java Transfer -todbms document.map document_in.xml
853
</PRE>
854

  
855
<P>When transferring data from the database to an XML document, use the command:</P>
856

  
857
<PRE>
858
   java Transfer -todbms &lt;map-file&gt; &lt;xml-file&gt; &lt;table-name&gt; &lt;key-value&gt;...
859
</PRE>
860

  
861
<P>where &lt;key-value> is one or more values in a single key. (There are multiple values only if the key is multi-part.) For example, to transfer data for sales order number 123 from the Sales table to the file sales_out.xml according to the map document sales.map, use the command:</P>
862

  
863
<PRE>
864
   java Transfer -toxml sales.map sales_out_in.xml Sales 123
865
</PRE>
866

  
867
<P>The Transfer application requires an ODBC data source named "xmldbms", an ODBC driver for that database, and that the tables referred to in the map exist in that database. Furthermore, if the map specifies that the system generate key values, the table XMLDBMSKey must exist; for more information, see de.tudarmstadt.ito.xmldbms.helpers.KeyGeneratorImpl.</P>
868

  
869
<h3><a name="GenerateMapSample"/>9.2 GenerateMap</h3>
870
<i>GenerateMap</i> is a simple command-line application that generates a map and a set of CREATE TABLE statements from a DTD, an XML document containing or referring to a DTD, or a DDML schema document. The map is saved in a document with the .map extension and the CREATE TABLE statements are saved in a document with the .sql extension. It shows how to use the MapFactory_DTD and Map classes.</P>
871

  
872
<P>To run GenerateMap, use the command:</P>
873

  
874
<PRE>
875
   java GenerateMap &lt;DTD or XML document&gt;
876
</PRE>
877

  
878
<P>For example, to generate a map from the document DTD, use the command:</P>
879

  
880
<PRE>
881
   java GenerateMap document.dtd
882
</PRE>
883

  
884
<P>The GenerateMap application requires an ODBC data source named "xmldbms" and an ODBC driver for that database. It does not require that the database contain any tables -- it simply needs to retrieve information from the database about how to construct the CREATE TABLE statements. </P>
885

  
886
<h3><a name="ConvertSchemaSample"/>9.3 ConvertSchema</h3>
887
<i>ConvertSchema</i> is a simple command-line application that converts schema documents to DTDs and vice versa. Currently, only DDML-to-DTD and DTD-to-DDML are supported, but writing converters to other schema languages is relatively easy -- a half day to day per direction. Although this sample has nothing to do with databases, it does show the capabilities of some of the schema conversion classes (SubsetToDTD, DDMLToDTD, DTDToDDML, and DTD), which might be useful in other applications.</P>
888

  
889
<P>To convert a schema document to a DTD or vice versa, use the command:</P>
890

  
891
<PRE>
892
   java ConvertSchema &lt;schema-file&gt;
893
</PRE>
894

  
895
<P>For example, to convert the document.ddm DDML document to a DTD, use the command:</P>
896

  
897
<PRE>
898
   java ConvertSchema document.ddm
899
</PRE>
900

  
901
<P>To convert a DTD to convert the document.dtd DTD to a DDML document, use the command:</P>
902

  
903
<PRE>
904
   java ConvertSchema document.dtd
905
</PRE>
906

  
907
<H2><A NAME="Tips"/>10.0 Tips and Tricks</H2>
908

  
909
<p>Here is a short list of ways that might help your code run faster:</p>
910

  
911
<ul>
912

  
913
<li>Reuse Map objects if you need to transfer data from multiple documents to the database or vice versa. For details, see section 3.0, "<a href="#Maps">Map Objects, Map Factories, and the XML-DBMS Mapping Language</a>".</li>
914

  
915
<li>Use a pool of SELECT statements when transferring data from the database to an XML file. For details, see the comments in the code for Map.checkInSelectStatement.</li>
916

  
917
<li>Close your prepared statements before discarding a Map object. For details, see Map.closeStatements().</li>
918

  
919
</ul>
920

  
921
<H2><A NAME="License"/>11.0 Licensing and Support</H2>
922

  
923
<P>XML-DBMS, along with its source code, is freely available for use in both commercial and non-commercial settings. It is not copyrighted and has <B>absolutely no warranty</B>. Use it as you will.</P>
924

  
925
<P>Although I am no longer at the Technical University of Darmstadt, you can still get limited support by emailing me at <A HREF="mailto:rpbourret@aol.com">rpbourret@aol.com</A> or <A HREF="mailto:rpbourret@hotmail.com">rpbourret@hotmail.com</A>. Because I will be travelling and not in regular contact with email, expect a one- to two-week delay. Bug reports and comments are welcome. There is also a list of <A HREF="BugsEnhancements.htm">known bugs and suggested enhancements</a>.</P>
926

  
927
<p>Thanks to all those who have given me feedback and sent in bug reports. Special thanks to Richard Sullivan, Matthias Pfisterer, and Alf Hogemark for their helpful comments, suggestions for new features, code, and testing.</p>
928

  
929
</BODY>
930
</HTML>
931

  
932 0

  
xmldbms/BugsEnhancements.htm
1
<html>
2
<head>
3
   <title>Bugs and Enhancements</title>
4
</head>
5
<body>
6

  
7
<H2>Bugs and Enhancements</H2>
8

  
9
<p>This file is a combination of <a href="#bugs">bugs</a> and potential future <a href="#enhance">enhancements</a>. It is not always clear which is which...</p>
10

  
11
<h3><a name="bugs">Known Bugs</a></h3>
12

  
13
<p><b>Title: </b>Reuse of prepared SELECT statements with JDBC-ODBC bridge and Access doesn't work<br />
14
<b>Description: </b>Either the JDBC-ODBC bridge or the MS Access driver does not correctly support the reuse of prepared SELECT statements. As a consequence, the code to reuse these statements has been commented out. If your driver does correctly support prepared SELECT statements, see the comments in Map.checkInSelectStmt for how to increase performance.</p>
15

  
16
<p><b>Title: </b>KeyGeneratorImpl doesn't work with Microsoft Access<br />
17
<b>Description: </b>KeyGeneratorImpl doesn't work with Microsoft Access. The problem is that the transaction that updates the XMLDBMSKey table is never committed, in spite of a call to do this. As a workaround, comment out the line of code that sets auto-commit to false. Presumably, this means there is
18
a possibility two users could receive the same high key value. Note that it is not clear whether the problem is with Microsoft Access itself or the ODBC driver supplied by Microsoft.</p>
19

  
20
<p><b>Title: </b>Namespace prefix "lost" of more than one prefix defined for same namespace<br />
21
<b>Description: </b>If more than one prefix is declared in SubsetToDTD.convertDocument or SubsetToDTD.convertExternalSubset, then the prefix actually used is the first one encountered in the DTD.</p>
22

  
23
<p><b>Title: </b>Order not supported when foreign key in parent<br />
24
<b>Description: </b>When the foreign key in a parent/child relationship between two element types-as-classes is in the table of the parent element type, order information can be saved for the 
25
child element type but not retrieved. For example, consider the following:</p>
26
<pre>
27
   &lt;SalesOrder&gt;
28
      &lt;Number&gt;123&lt;/Number&gt;
29
      &lt;Customer&gt;
30
         &lt;Name&gt;ABC Industries&lt;/Name&gt;
31
         &lt;Address&gt;123 Main St., Chicago&lt;/Address&gt;
32
      &lt;/Customer&gt;
33
   &lt;/SalesOrder&gt;
34
</pre>
35
<p>If the foreign key used to join the sales order and customer tables is in the sales order table, then no information about the order in which the Customer element appears in the SalesOrder element can be retrieved from the database. The problem here is that the code to construct SELECT statements and the code to access data in result sets assumes that SELECTs are done over a single table. In this case, the order column for the Customer element is stored in the Sales table, so a join to the Sales table needs to be done when retrieving customer data. Fixing this is likely to require some rethinking in the way in which the statement-generation code in Map and data retrieval code in Row (as well as elsewhere) works.</p>
36

  
37
<p><b>Title: </b>Root table assumed to have a key<br />
38
<b>Description: </b>If the root table does not have a candidate key, then the DocumentInfo object returned by DOMToDBMS.storeDocument() cannot be used to retrieve the data. It is also quite likely that some code will fail, although this has not been tested.</p>
39

  
40
<p><b>Title: </b>Columns with markup not expanded<br />
41
<b>Description: </b>When a column containing markup is retrieved from the database, it is not expanded into the corresponding DOM nodes. Instead, it remains as marked up text.</p>
42

  
43
<p><b>Title: </b>Markup not escaped on serialization<br />
44
<b>Description: </b>Any markup that occurs when serializing a Map or DDML document is not replaced with entities as it should be. XMLOutputStream.characters needs to be fixed.</p>
45

  
46
<p><b>Title: </b>Markup characters not serialized correctly<br />
47
<b>Description: </b>The code that serializes the contents of a DOM node needs to know how to serialize markup characters that are not true markup. For example, if an element contains &quot;a&lt;b&quot;, how should the &lt; character be serialized? If it is serialized as a &lt; character, it will generate an error when it is retrieved from the database, as the code will try to parse it as markup. If it is serialized as the entity &amp;lt;, the data in the database cannot be searched for the expected text, but must instead be searched for the &amp;lt; entity usage. Which route to follow should be left as a choice for the user -- probably designated on a per-element-type basis in the mapping document.</p>
48

  
49
<p><b>Title: </b>Duplicate keys not handled correctly?<br />
50
<b>Description: </b>If the code encounters a duplicate key value when inserting data into the database, it returns an error. Although this makes sense in some cases -- for example, it is clearly an error to insert the same sales order twice -- it does not make sense in others. For example, suppose part information is sent with each sales order. Because multiple sales orders can refer to the same part, all sales orders after the first that refer to a given part will fail because they get a duplicate key error inserting the part information. One possible solution to this is to ignore duplicate key errors when the foreign key in the parent/child relationship is in the table of the parent element; in such a situation, the contents of the child and all its children would presumably be ignored. However, because it is not clear what to do in this case, the best solution for the moment is to simply throw the duplicate key error and find out how people are using the software and what they expect.</p>
51

  
52
<p><b>Title: </b>Empty elements-as-classes inserted as row of all NULLs<br />
53
<b>Description: </b>If an element-as-class is empty and has no attributes, the code (probably) inserts in a row with all NULLs into the database, which will often cause an INSERT error. It is not clear whether this is the correct behavior.</p>
54

  
55
<p><b>Title: </b>SubsetToDTD ignores encoding declarations<br />
56
<b>Description: </b>SubsetToDTD ignores encoding declarations, instead depending on the native abilities of Java to decode the bytes. This will most likely be encountered while using MapFactory_DTD.</p>
57

  
58
<h3><a name="enhance">Future Enhancements</a></h3>
59

  
60
<p>Some of these changes are probably not that difficult; others will require a lot of work. If you are interested in implementing any of these, you might want to send me email first, as I can often explain what needs to be done and where the potential problems lie.</p>
61

  
62
<p><b>Title: </b>Pass-through classes<br />
63
<b>Description: </b>Pass-through is a way to compress structure that exists in the XML document but not in the database. The simplest example of pass-through is the IgnoreRoot element in the XML-DBMS mapping language. However, much more sophisticated types of pass-through as possible as well. For example, imagine that you have an Address element inside a Customer element and the Address element contains Street, City, PostCode, etc. elements. In the object-tree view supported by XML-DBMS, Address would generally require its own table. However, in many cases it is desirable to eliminate the Address element and store Street, City, PostCode directly in the Customer table.</p>
64

  
65
<p>Pass-through like this is relatively easy when transferring data from XML documents to the database, but can prove impossible in the other direction, as multiple XML structures can be mapped to the same database structure. More sophisticated types of pass-through are imaginable as well. For more information, see <a href="PassThrough.txt">PassThrough.txt</a>.</p>
66

  
67
<p><b>Title: </b>Binary data not supported<br />
68
<b>Description: </b>Binary data is not supported either internally (Base64) or externally (unparsed 
69
entities).</p>
70

  
71
<p><b>Title: </b>CREATE TABLE statements inadequate<br />
72
<b>Description: </b>Currently, CREATE TABLE statements have a number of drawbacks. 1) They do not correctly support DECIMAL and NUMERIC columns. 2) They use hard-coded data type names instead of querying the database for these names. 3) They do not state whether columns are nullable. 4) They do not include primary key / foreign key constraints. None of these should be difficult to fix except possible the primary key / foreign key constraints.</p>
73

  
74
<p><b>Title: </b>Map construction code is a mess<br />
75
<b>Description: </b>The code in the Temp*Map classes is a mess, especially TempMap. (The map factory code is generally pretty good.) The problem is that the Temp*Map classes do not have well-defined interfaces, allowing direct access to class variables instead. Thus, writing map factories can be very confusing and the maps themselves never really track whether they are in a valid or invalid state. Furthermore, the code is poorly commented, especially TempMap.java. For more information, see <a href="TempMap.txt">TempMap.txt</a>.</p>
76

  
77
<p><b>Title: </b>No pretty printing<br />
78
<b>Description: </b>The code that serializes the contents of a DOM node needs to have pretty-printing options: a) indent nested elements, b) normalize carriage return/line feeds as spaces, c) insert line breaks at a specified line length.</p>
79

  
80
<p><b>Title: </b>Code to order DOM nodes very inefficient<br />
81
<b>Description: </b>When retrieving data from the database, the code that inserts ordered child nodes into a parent node is very inefficient. It uses a linear search to determine where to place the child. This code should be rewritten, possibly using a binary search.</p>
82

  
83
<p><b>Title: </b>Number formats<br />
84
<b>Description: </b>Currently, there is no way to specify the format of numbers in the XML document. It should be relatively easy to support this in a manner similar to date formats through an option in the mapping file. See the XMLDBMS DTD, MapFactory_MapDocument, Parameters, and DBMSToDOM for ideas.</p>
85

  
86
<p><b>Title: </b>Per-property formats<br />
87
<b>Description: </b>In many cases, it is useful to assign date/time or number formats on a per-property basis. This is most easily done by adding a Name attribute to the formats described in the mapping document (type ID) and optional Formats subelements to property maps. The Formats subelement would have IDREF attributes for the number and date/time formats to use (e.g. Number, DateTime). These must refer to formats defined in the Options element. If present, they would be used; if not present, the default format (defined in the Options element) would be used.</p>
88

  
89
<p><b>Title: </b>Rewrite DOMToDBMS as SAX application<br />
90
<b>Description: </b>It is possible that DOMToDBMS can be rewritten as a SAX application. If done, the result should be named SAXToDBMS and DOMToDBMS left in the package, as it will sometimes be useful to pass a DOM tree to the database. For more information, see <a href="SAXToDBMS.txt">SAXToDBMS.txt</a>.</p>
91

  
92
</body>
93
</html>
94 0

  
xmldbms/xmldbms.dtd
1
<!--
2
   No copyright, no warranty; use as you will.
3
   Written by Ronald Bourret, Technical University of Darmstadt, 1998-9
4
-->
5

  
6
<!--
7
   XML-DBMS is a system for transferring data between XML documents
8
   and relational databases. It views an XML document as a tree of
9
   objects and then uses an object-relational mapping to map these
10
   objects to a relational database.
11

  
12
   Generally, element types are viewed as classes, and attributes and
13
   PCDATA are viewed as properties of those classes. However, element
14
   types can also be viewed as properties of their parent element
15
   type. Although this is most useful when an element type contains
16
   only PCDATA, it is useful in other cases as well. For example,
17
   consider an element type that contains a description written in
18
   XHTML. Although this description has subelements such as <B> and
19
   <P>, these subelements cannot be meaningfully interpreted on their
20
   own and it makes more sense to view the contents of the element
21
   type as a single value (property) rather than a class.
22

  
23
   (Note that the tree of objects is *not* the DOM. This is because
24
   the DOM models the document itself, not the data in that document.)
25

  
26
   The XML-DBMS mapping language, which is described in this DTD,
27
   allows users to:
28

  
29
   a) Declare how element types are to be viewed (as classes or
30
      properties),
31

  
32
   b) Declare which subelements, attributes, and PCDATA are to be
33
      viewed as properties of a given element type-as-class (unmapped
34
      XML structures are ignored), and
35

  
36
   c) State how to map the resulting classes and properties to the
37
      database.
38

  
39
   The resulting object-relational mapping maps classes to tables and
40
   properties to either columns in those tables or to subtables. (The
41
   latter is useful, for example, for storing BLOB properties
42
   separately.) Inter-class relationships are mapped as candidate key
43
   / foreign key relationships. The mapping can also state whether to
44
   preserve information about the order in which subelements and
45
   PCDATA occur within their parent, which is generally important in
46
   document-centric XML documents and unimportant in data-centric XML
47
   documents.
48
-->
49

  
50
<!-- 
51
   The XMLDBMS element type is the root element type of the
52
   mapping document.
53
 -->
54

  
55
<!ELEMENT XMLToDBMS (Options*, Maps)>
56
<!ATTLIST XMLToDBMS
57
          Version CDATA #FIXED "1.0">
58

  
59
<!--
60
   Options is simply a container to hold the various options you
61
   can set.
62
-->
63

  
64
<!ELEMENT Options (EmptyStringIsNull?, DateTimeFormats?, Namespace*)>
65

  
66
<!--
67
   The EmptyStringIsNull element states how empty strings in an
68
   XML document correspond to NULLs in the database. Technically,
69
   NULL means that there is no value and is distinct from an empty
70
   string. In an XML document, this corresponds to an optional
71
   element or attribute being missing, as opposed to its being
72
   present and having an empty string as its value (this includes
73
   empty elements).
74

  
75
   However, many XML users are likely to think of empty strings
76
   as NULLs. EmptyStringIsNull allows XML-DBMS users to handle
77
   this situation. If it is present, empty strings are treated
78
   the same as NULLs; if it is absent, empty strings are treated
79
   as strings.
80

  
81
   The following table shows how NULL values and empty strings in
82
   the database are transferred to missing elements/attributes and
83
   empty strings in the XML document and vice versa.
84

  
85

  
86
                                     Transfer Direction
87
                          _______________________________________
88
       EmptyStringIsNull |                   |                   |
89
          element is:    |  DBMS  =>  XML    |    XML  =>  DBMS  |
90
      ___________________|___________________|___________________|
91
     |                   |                   |                   |
92
     |                   | NULL   => missing | missing => NULL   |
93
     |    not present    |                   |                   |
94
     |                   | empty  => empty   | empty   => empty  |
95
     |                   | string    string  | string     string |
96
     |___________________|___________________|___________________|
97
     |                   |                   |                   |
98
     |                   | NULL   => empty   | missing => NULL   |
99
     |                   |           string  |                   |
100
     |     present       |                   |                   |
101
     |                   | empty  => empty   | empty   => NULL   |
102
     |                   | string    string  | string            |
103
     |___________________|___________________|___________________|
104
   
105

  
106
   Note that EmptyStringIsNull applies only to elements and
107
   attributes mapped as properties. (An empty element-as-class with
108
   no attributes results in a row of all NULLs in the database.) 
109
-->
110

  
111
<!ELEMENT EmptyStringIsNull EMPTY>
112

  
113
<!--
114
   The DateTimeFormats element and its subelements specify the formats
115
   used to parse dates, times, and timestamps. The information specified
116
   here is used to construct one of Java's date formatting objects -
117
   either a java.text.DateFormat or a java.text.SimpleDateFormat.
118

  
119
   The value of the Language attribute must be a valid ISO Language Code.
120
   These are defined by ISO-639 and are available on the Web. For example,
121
   try:
122

  
123
      http://www.ics.uci.edu/pub/ietf/http/related/iso639.txt 
124

  
125
   The value of the Country attribute must be a valid ISO Country Code.
126
   These are defined by ISO-3166 and are also available on the Web. For
127
   example, try:
128

  
129
      http://www.din.de/gremien/nas/nabd/iso3166ma/codlstp1.html
130

  
131
   The value of Date, Time, and Timestamp attributes must be either one
132
   of the keywords FULL, LONG, MEDIUM, or SHORT, whose formats are
133
   described in the documentation for DateFormat, or a formatting
134
   pattern as defined in the documentation for SimpleDateFormat. Which
135
   format is used depends on the data type of the target column. (If
136
   values are not being formatted correctly, be sure to check how the
137
   JDBC driver maps the type of the target column. For example,
138
   MS Access only supports TIMESTAMP columns.)
139

  
140
   If an element is missing, the default value is used. For example, if
141
   the Locale element is missing, the default locale is used. If the
142
   DateTimeFormats element is missing, the default locale and format
143
   are used. Note that Locale is used only if Date, Time, or Timestamp
144
   is present.
145
-->
146

  
147
<!ELEMENT DateTimeFormats (Locale?, Patterns)>
148
<!ELEMENT Locale EMPTY>
149
<!ATTLIST Locale
150
          Language NMTOKEN #REQUIRED
151
          Country NMTOKEN #REQUIRED>
152
<!ELEMENT Patterns EMPTY>
153
<!ATTLIST Patterns
154
          Date CDATA #IMPLIED
155
          Time CDATA #IMPLIED
156
          Timestamp CDATA #IMPLIED>
157

  
158
<!--
159
   Namespace elements give URIs and their associated prefixes. These
160
   are used as follows:
161

  
162
   a) In the mapping document, prefixes identify which namespace an
163
      element or attribute belongs to. They can be used in the Name
164
      attribute of the ElementType and Attribute element types.
165

  
166
   b) When transferring data from an XML document to the database,
167
      namespace URIs are used to identify elements and attributes in
168
      that document. The XML document can use different prefixes than
169
      are used in the mapping document.
170

  
171
   c) When transferring data from the database to an XML document,
172
      namespace URIs and prefixes are used to prefix element and
173
      attribute names in that document.
174

  
175
   Namespace elements are not required. If they are used, the same URI
176
   or prefix cannot be used more than once. Zero-length prefixes ("")
177
   are not currently supported.
178
-->
179

  
180
<!ELEMENT Namespace EMPTY>
181
<!ATTLIST Namespace
182
          Prefix NMTOKEN #REQUIRED
183
          URI CDATA #REQUIRED>
184

  
185
<!ELEMENT Maps (IgnoreRoot*, ClassMap+)>
186

  
187
<!--
188
   IgnoreRoot elements instruct the transfer software to ignore the
189
   root element of the XML document (when transferring data from an
190
   XML document to the database) or to construct an enclosing root
191
   element (when transferring data from the database to an XML
192
   document). This is useful when a document contains multiple,
193
   unrelated instances of a particular class.
194

  
195
   For example, suppose a document contains multiple sales orders:
196
   each sales order is represented by a SalesOrder element and a
197
   single Orders element serves as the root of the document. If the
198
   sales orders are unrelated - that is, no information is stored in
199
   the database about which sales orders are in this particular
200
   document - then the root element of the document (Orders) should
201
   be ignored.
202

  
203
   The ElementType sub-element of IgnoreRoot identifies the root
204
   element type to be ignored. A given map can identify multiple roots
205
   that are to be ignored.
206

  
207
   The PseudoRoot sub-elements of IgnoreRoot identify the mapped
208
   children of the ignored root. Each is identified by its ElementType
209
   and must be mapped separately in a ClassMap element. CandidateKey
210
   (optional) gives the candidate key in the table to which the
211
   pseudo-root element is mapped and OrderColumn (optional) gives the
212
   column containing information about the order in which the
213
   pseudo-root occurs in the actual root.
214
-->
215

  
216
<!ELEMENT IgnoreRoot (ElementType, PseudoRoot+)>
217
<!ELEMENT PseudoRoot (ElementType, CandidateKey?, OrderColumn?)>
218

  
219
<!--
220
   ClassMap elements state that an element type (identified by the
221
   ElementType subelement) is to be treated as a class. They also
222
   provide information about the properties of that class (PropertyMap
223
   subelements), any classes that are related to the class
224
   (RelatedClass subelements), and how to map that class to the
225
   database (ToRootTable and ToClassTable subelements).
226

  
227
   A root table is any table that can be used as the top-level table
228
   when extracting data from the database. The CandidateKey and
229
   OrderColumn subelements give the columns that are used in the
230
   WHERE and ORDER BY clauses when extracting data. The root element
231
   type must be mapped as either ToRootTable or IgnoreRoot.
232
-->
233

  
234
<!ELEMENT ClassMap (ElementType,
235
                    (ToRootTable | ToClassTable),
236
                    PropertyMap*, RelatedClass*)>
237

  
238
<!ELEMENT ToRootTable (Table, CandidateKey?, OrderColumn?)>
239
<!ELEMENT ToClassTable (Table)>
240

  
241
<!--
242
   PropertyMap elements state that an attribute, PCDATA, or element
243
   type is to be treated as a property. The property is identified by
244
   the Attribute, PCDATA, or ElementType subelement and belongs to the
245
   class in whose ClassMap the PropertyMap is nested.
246

  
247
   Attributes and PCDATA can be properties only of their parent
248
   element type-as-class. An element type can be a property of any
249
   parent element type. Thus, an element type can be declared to be a
250
   property of more than one element type-as-class.
251

  
252
   Property values are stored in columns. These can be either in the
253
   class table (ToColumn) or in a separate table (ToPropertyTable). In
254
   the latter case, Table identifies the property table, and
255
   CandidateKey and ForeignKey identify the keys used to join the two
256
   tables.
257

  
258
   The OrderColumn subelement designates the column in which the
259
   system stores order information. For more information, see
260
   OrderColumn below.
261
-->
262

  
263
<!ELEMENT PropertyMap ((Attribute | PCDATA | ElementType),
264
                       (ToColumn | ToPropertyTable),
265
                       OrderColumn?)>
266

  
267
<!ELEMENT ToColumn (Column)>
268
<!ELEMENT ToPropertyTable (Table, CandidateKey, ForeignKey, Column)>
269
<!ATTLIST ToPropertyTable
270
          KeyInParentTable (Candidate | Foreign) #REQUIRED>
271

  
272
<!--
273
   RelatedClass elements describe classes that are related to
274
   the class being defined. In class terms, you can think of
275
   this as meaning that a property is added to the class being
276
   defined that points to the related class. In XML terms, this
277
   means that the element type for the related class is a child
278
   of the element type for the class being defined.
279

  
280
   (Note that the term "child class" could have been used here,
281
   but wasn't due to the potential for confusion with parent/
282
   child table relationships, parent/child element
283
   relationships, and class inheritance relationships.)
284

  
285
   For example, in the following XML document, if the element
286
   types <A> and <B> are mapped as classes, then <B> needs to
287
   be defined as a related class of <A>.
288

  
289
      <A>
290
         <property_A1>123</property_A1>
291
         <property_A2>abcde</property_A2>
292
         <B>
293
            <property_B1>123</property_B1>
294
            <property_B2>abcde</property_B2>
295
         </B>
296
      </A>
297
            
298

  
299
   The RelatedClass element specifies the element type of the
300
   related class, the candidate and foreign keys used to join
301
   the tables for the two classes, and the name of the column
302
   (if any) which contains the order in which the elements for
303
   the related class appear in the class being defined.
304
-->
305

  
306
<!ELEMENT RelatedClass (ElementType,
307
                        CandidateKey, ForeignKey,
308
                        OrderColumn?)>
309
<!ATTLIST RelatedClass
310
          KeyInParentTable (Candidate | Foreign) #REQUIRED>
311

  
312
<!--
313
   The CandidateKey and ForeignKey elements describe the keys used to
314
   join two tables: either two class tables or a class table and a
315
   property table. Which key occurs in the parent table is declared in
316
   the RelatedClass or ToPropertyTable element with the
317
   KeyInParentTable attribute.
318

  
319
   In addition, the CandidateKey element is used to identify the
320
   columns used to identify rows when extracting data from the root
321
   table.
322

  
323
   The Generate attribute tells the system whether to generate the
324
   candidate key. If the key is generated, the user must provide a
325
   class that generates the key; for more information, see:
326

  
327
      de.tudarmstadt.ito.xmldbms.KeyGenerator
328
      de.tudarmstadt.ito.xmldbms.helpers.KeyGeneratorImpl
329

  
330
   If the key is not generated, other properties must be mapped to
331
   the key columns.
332
-->
333

  
334
<!ELEMENT CandidateKey (Column+)>
335
<!ATTLIST CandidateKey
336
          Generate (Yes | No) #REQUIRED>
337
<!ELEMENT ForeignKey (Column+)>
338

  
339
<!--
340
   ElementType, Attribute, and PCDATA elements are used to identify
341
   the corresponding XML structures.
342

  
343
   The MultiValued attribute of the Attribute element type states
344
   whether individual tokens in an attribute are separate values
345
   (NMTOKENS, IDREFS, and ENTITIES attributes) or a single value
346
   (CDATA, ID, IDREF, ENTITY, and NMTOKEN attributes).
347
-->
348

  
349
<!ENTITY % XMLName "Name NMTOKEN #REQUIRED">
350
<!ELEMENT ElementType EMPTY>
351
<!ATTLIST ElementType
352
          %XMLName;>
353
<!ELEMENT Attribute EMPTY>
354
<!ATTLIST Attribute
355
          %XMLName;
356
          MultiValued (Yes | No) "No">
357
<!ELEMENT PCDATA EMPTY>
358

  
359
<!--
360
   Table, Column, and OrderColumn names are used to identify the
361
   corresponding XML structures. Table and column names must follow
362
   the naming conventions used in the database. For example, if
363
   column names are stored in upper case in the database, then they
364
   must be specified in upper case in the mapping document. Table
365
   names may be qualified with catalog and schema names. Column names
366
   must not be qualified; the table to which they belong is determined
367
   from context (see below). Column names must not be quoted; the system
368
   quotes them before using them in SQL statements.
369

  
370
   When transferring data from the database to an XML document, the
371
   special table name "Result Set" is used when the root table is a
372
   result set.
373

  
374
   The table to which a column belongs is determined as follows:
375

  
376
   Column element in:        Column occurs in:
377
   __________________        ________________________________________
378

  
379
   ToColumn                  Class table
380
   ToPropertyTable           Property table
381
   CandidateKey              Determined by KeyInParentTable attribute
382
   ForeignKey                Determined by KeyInParentTable attribute
383

  
384
   OrderColumn element in:   Column occurs in:
385
   __________________        ________________________________________
386

  
387
   PseudoRoot                Class table of pseudo-root element
388
   PropertyTable             Class table
389
                               (if property mapped as ToColumn)
390
                             Same table as foreign key
391
                               (if property mapped as ToPropertyTable)
392
   RelatedClass              Same table as foreign key
393

  
394
   Order columns are used to store information about the order in
395
   which elements and PCDATA occur in their parent element, as well as
396
   the order of values in multi-valued attributes (IDREFS, NMTOKENS,
397
   and ENTITIES).
398

  
399
   Storing order information is optional; if it is not stored, there
400
   is no guarantee that order will be preserved in a round trip from
401
   an XML document to the database and back again. (Note that nesting
402
   is preserved; that is, subelements and PCDATA always occur in the
403
   correct parent.)
404

  
405
   The Generate attribute of the OrderColumn element tells the system
406
   whether to generate order information or not. (The presence or
407
   absence of the OrderColumn element tells the system whether to use
408
   order information.) If order information is generated, the order
409
   column must be of type java.sql.Types.Integer. If order information
410
   is not generated, another property must be mapped to the order
411
   column.
412
-->
413

  
414
<!ENTITY % DatabaseName "Name CDATA #REQUIRED">
415
<!ELEMENT Table EMPTY>
416
<!ATTLIST Table
417
          %DatabaseName;>
418
<!ELEMENT Column EMPTY>
419
<!ATTLIST Column
420
          %DatabaseName;>
421
<!ELEMENT OrderColumn EMPTY>
422
<!ATTLIST OrderColumn
423
          %DatabaseName;
424
          Generate (Yes | No) #REQUIRED>
425

  
426 0

  
... This diff was truncated because it exceeds the maximum size that can be displayed.

Also available in: Unified diff