Transferring data between XML documents and relational databases
Category: Technical
<< Buy This Book on Amazon >>
264 views since 2007-05-11, updated at 2007-05-27.
Description
1) Overview
In this paper we will
discuss strategies for transferring data between XML documents and
relational databases according to two mappings (a table-based mapping
and an object-based mapping) commonly used to map DTDs to relational
databases. Although the discussion largely focuses on the difference
between using SAX- and DOM-based tools to transfer data, it also
discusses a number of strategies for traversing both the XML and
database hierarchies and the tradeoffs among them.
IMPORTANT:
The table-based mapping and the object-based mapping are not discussed
in this paper. However, you must understand them before reading this
paper. For more information, see Mapping DTDs to Databases.
WARNING:
This is not the best paper I have ever written, largely due to lack of
time to research all of the issues involved. If you find factual errors
-- I'm sure there are more than what have already been found -- please
contact me. Thanks.
2) Table-based mapping
The
table-based mapping views an XML document as a serialized table. That
is, the structure of the document must be as follows, where the
outermost (
contains more than one table:
|
... ...... ...
... ......
The
table-based mapping has the advantage of simplicity, which makes it
useful as a model for writing data transfer tools. However, because the
model applies only to a limited set of XML documents, the tools are of
limited use. They are most useful for using XML to transfer data
between relational databases or for providing single-table access to
the database.
For a complete discussion of the table-based mapping, see see Mapping DTDs to Databases".
2.1) Transferring data from XML to the database
The code to transfer data from XML to the database follows a common pattern, regardless of whether it uses SAX or DOM:
- Table element start: prepare an INSERT statement
- Row element start: clear INSERT statement parameters
- Column elements: buffer PCDATA and set INSERT statement parameters
- Row element end: execute INSERT statement
- Table element end: close INSERT statement
The
code does not make any assumptions about the names of the tags. In
fact, it uses the name of the table-level tag to build the INSERT
statement and the names of the column-level tags to identify parameters
in the INSERT statement. Thus, these names could correspond exactly to
the names in the database or could be mapped to names in the database
using a configuration file.
Here is the code using SAX for a document containing a single table:
int state = UNKNOWN; PreparedStatement stmt; StringBuffer data; public void startElement(String uri, String name, String qName, Attributes attr) { if (state == UNKNOWN) { stmt = getInsertStmt(name); state = TABLE; } else if (state == TABLE) { state = ROW; stmt.clearParameters(); } else if (state == ROW) { state = COLUMN; data = new StringBuffer(); } else { // if (state == COLUMN) throw new SAXException("XML document nested too deep."); } } public void characters (char[] chars, int start, int length) { if (state == COLUMN) data.append(chars, start, length); } public void endElement(String uri, String name, String qName) { if (state == TABLE) { stmt.close(); state = UNKNOWN; } else if (state == ROW) { stmt.executeUpdate(); state = TABLE; } else if (state == COLUMN) { setParameter(stmt, name, data.toString()); state = ROW; } else { // if (state == UNKNOWN) throw new SAXException("Invalid program state."); } } And here is the code using DOM for a document containing a single table:
void processTable(Document doc) { Element table = doc.getDocumentElement(); PreparedStatement stmt = getInsertStmt(table.getNodeName()); Element row = (Element)table.getFirstChild(); while (row != null) { stmt.clearParameters(); processRow(stmt, row); row = row.getNextSibling(); } } void processRow(PreparedStatement stmt, Element row) { Element column = (Element)row.getFirstChild(); while (column != null) { processColumn(stmt, column); column = column.getNextSibling(); } stmt.executeUpdate(); } void processColumn(PreparedStatement stmt, Element column) { String data = getTextChildren(column); setParameter(stmt, column.getNodeName(), data); } As you can see, the code is functionally identical, the only difference being the use of SAX or DOM.
Free register and download UseNet downloader, then you can free download ebooks from UseNet.Free Download "Transferring data between XML documents and relational databases" from Usenet!
Disclaimer:
Contents of this page are indexed from the Internet. All actions are under your responsability. Email us to report illegal contents or external links and we'll remove them immediately.
Search More...
Transferring data between XML documents and relational databasesLinks
Free Trade Magazine Subscriptions & Technical Document DownloadsSearch and Buy
<< Search and Buy This Book on Amazon >>
How to download:Free register to download UseNet downloader and install, then search book title and start downloading. UseNet is clean and can be unstalled totally. Enjoy!
Free Download "Transferring data between XML documents and relational databases" from Usenet!
Download Link 2
How to Download
You may need eMule or Bittorrent to download ebook torrents or emule links.
Report Dead Link
Please leave a comment to report dead links, so that someone else may update new links.
Related Books
- Ebooks list page : 87
- Information Modeling and Relational Databases, Second Edition (The Morgan Kaufmann Series in Data Management Systems)
- Transferring Data
- Design and Use of Relational Databases in Chemistry
- Java.Persistence.for.Relational.Databases
- Java Persistence for Relational Databases
- Information Modeling and Relational Databases
- Design and Use of Relational Databases in Chemistry
- Java Persistence for Relational Databases
- Inside Relational Databases with Examples in Access
- Inside Relational Databases with Examples in Access
- Inside Relational Databases with Examples in Access
- [share_ebook] Design and Use of Relational Databases in Chemistry
- Theory and Practice of Relational Databases, Second Edition
- Schaum's Outline of Fundamentals of Relational Databases
- Inside Relational Databases with Examples in Access
Comments
Add Your Comments
- Download links and password may be in the description section, read description carefully!
- Do a search to find mirrors if no download links or dead links.




