Java Reference
In-Depth Information
 
Store each record as an element, with field data in child elements.
The advantage of using attributes is that the XML file is shorter, since the attribute name occurs only
once. If you store the data in an element, the name occurs twice: once in opening the element and once
in closing it. The attribute-based approach is shown here:
<CUSTOMER FIRST_NAME=" Michael" MI="A" LAST_NAME="Corleone" STREET="123
Pine"/>
The alternative approach, which uses child elements for each data item, is more verbose but more
structured, as shown in Listing 19-1 .
Listing 19-1: Customer data record in XML
<?xml version="1.0"?>
<CUSTOMERS>
<CUSTOMER CUSTOMER_NUMBER="100">
<FIRST_NAME>Michael</FIRST_NAME>
<MI>A</MI>
<LAST_NAME>Corleone</LAST_NAME>
<STREET>123 Pine</STREET>
<CITY>New York</CITY>
<STATE>NY</STATE>
<ZIP>10006</ZIP>
<PHONE>201-555-1212</PHONE>
</CUSTOMER>
</CUSTOMERS>
Clearly, as exemplified by the CUSTOMER_NUMBER field in Listing 19-1 , you can also use a combination
of these two approaches. There is no "best" way. My Linux PDA uses the attribute-oriented approach,
presumably to save space. Most XML documents used as INI files use the element-based approach,
presumably for readability.
The JDBC driver described in this chapter supports the insertion of data as an attribute by defining a
custom data type: ATTRIBUTE . Other data types are always inserted as child elements. In practice,
there can really only be one other type: VARCHAR , since all data in an XML document is represented as
a String . The details of the JDBC driver are discussed in the next section .
Building a JDBC-accessible XML DBMS
There are two main components required to build an XML database system incorporating a JDBC
programming interface: JDBC driver classes and the SQL engine.
In designing the JDBC API, Sun foresaw the need for implementations of a subset intended for
lightweight databases that would not provide full support for the API and SQL 92 Entry Level. The
method jdbcCompliant() is defined in the java.sql.Driver interface, specifically to indicate
compliance or noncompliance with the standard.
Although building a highly efficient, fully compliant JDBC driver is a significant undertaking,
implementing a useful subset is a much simpler task.
The Implementation Base Classes
Search WWH ::




Custom Search