On Monday, April 1, 2002, at 02:33  PM, Jay Fitzgerald wrote:

> Can this be done and am I going about it the right way?

Are you familiar with something called "partial decomposition"?  I'm not 
sure where it came from, but Google suggests that it may have been 
conceived by Daniel Appelquist, the author of a book called "XML and 
SQL".  I read this book a few weeks ago -- it's expensive, and slim on 
content (see my mini-review below), but covers a topic that everyone 
seems very interested in.  I was elated when Google pointed me to this 
article on the theory of partial decomposition (by Appelquist) but 
dismayed to find that he didn't submit it in time for a conference, and 
so it is not actually found at this link: 
But I'm sure it's the same idea he puts forth in his book.

Partial Decomposition:
The idea is that you store your information in an XML document, and then 
take the most-searched information and store it in a database with some 
kind of relationship to the document (either store the XML document in 
the database or store a URI to the XML document in the database).  In 
this fashion, you can use the power of SQL to search for your data, but 
have the data itself stored in XML to take advantage of XML's features.  
The important thing to remember is that the data in the columns should 
ONLY be used for searches, and the XML is where the data TRULY lies, 
otherwise you can violate data integrity.  It is not a good scheme for 
data that is regularly changed or updated -- for this you are better off 
storing your data in the usual way.  Also, some of the methods for 
ensuring data integrity are not at this time possible in MySQL (he uses 
Oracle and SQL Server for a lot of his examples), though you can ad-lib 
it with your application (i.e. in PHP) if you are dilligent and are 
careful not to make changes to your database without going through the 
proper channels to ensure that data integrity is maintained.

It is no substitute for a true XML database, since it is just that -- a 
"partial" decomposition of your data (and thus is only "partially" 
searchable), and won't work for every application.  But you may wish to 
check out Appelquist's book.

(* my mini-review of "XML and SQL" by Daniel Appelquist:  Well, there 
aren't a lot of pages, the text is huge, and the book still costs US 
$40.00.  Kind of ridiculous.  This is further exacerbated by the fact 
that only 80% of the book actually revolves around ideas of using XML 
with SQL, and much of the rest of the book focuses on the process of 
developing a web application by taking user surveys and 
scenario-role-playing etc, or introducing some of the fundamentals of 
XML which are available all over the rest of the bookstore.  Excellent 
topics, which IMHO do not fall under the topic of 'XML and SQL'.  The 
book also discusses at length some of the XML features of Oracle and SQL 
Server, so I kind of skipped over these sections -- I'm a MySQL fan.

Is it worth reading?  The middle few chapters, which deal specifically 
with partial decomposition, are interesting.  But is it worth $40?  Not 
unless your employer is paying for it, or if you are looking for a 
general book on developing web applications.  In fact, it should 
probably have been called "Developing Web Applications with XML and 
SQL", and if it had then this review might be more forgiving.)

To answer your question, I'm not so sure that I would go about it the 
way that you have -- it seems that you are echoing an XML file from SQL 
information.  There's nothing wrong with this, but simply echoing it to 
the screen is probably more useless than just echoing the data in some 
meaningful format -- such as a paragraph or a list.  HOWEVER, if you 
were  storing the data in a file, or a string to be sent out as a SOAP 
or XML-RPC request, then that makes more sense.

Still, you want some advice?  First, your SQL code won't work as it 
is -- you've forgotten a mysql_fetch_* function to pull the data from 
the $sql_result.  So, add to your code:

while ($xml_data_row = mysql_fetch_assoc($sql_result)) {
   $xml_document = '<?xml version="1.0" encoding="utf-8" ?>
       <name>' . $xml_data_row['name'] . '</name>
       <address>' . $xml_data_row['address'] . '</address>
       <city>' . $xml_data_row['city'] . '</city>
       <state>' . $xml_data_row['home'] . '</state>

echo $xml_document;

This saves you a ton of typing and even makes your code look better.




Erik Price
Web Developer Temp
Media Lab, H.H. Brown

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to