#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Posts
    3
    Rep Power
    0

    xml an alternative to databases??


    I've been using MySQL for a few years now and give almost all my sites dynamic content with it. The MySQL server (and most database servers for that matter) is fast at retrieving/updating information. And isn't this the whole point? Reliable, fast access to your data?

    Anyway as I've been reading about XML I can't help shaking the feeling that it's just an alternative to using a database server. The features of XML, formatting abstraction, etc.. are what happens naturally when using a database.

    I don't see any reason why I'd want to move my data from my MySQL database into xml files stored on disk. I can see possibly writing some scripts to export the data into xml to be distributed, but the main use of the data would primarily happen via MySQL.

    What am I missing here?
    Thanks in advance, Jeremiah
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 1999
    Location
    California
    Posts
    43
    Rep Power
    15
    XML is a way of easily sharing your data, other than dumping it in comma-separated files.
    I wouldn't replace my database with a set of XML files, unless you are doing really basic stuff in your mySQL database.

    Iwan
  4. #3
  5. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    A few other points to consider:

    1) XML stores data heirarchically. If this is the structure you need, and especially if the heirarchy is complex, duplicating the relationships that the data have to one another in an RDBMS is much more complicated than using XML.

    2) You don't have to convert XML to HTML to display it (sometimes). Browsers with XML support, and servers with XSL support, mean you can display the XML directly, but still have the benefit of the structured organization.

    3) It's much easier to combine databases if they're both in XML. You can define translations between tags that allow for the same queries you run currently to work on a different set of data. This is great for large data repositories (think public/university libraries), where everybody has a seperate database but all want to be able share. This is the whole point of XML, really, the "semantic web" that the w3c is trying to create.

    And then there's the whole open format, ease of access/manipulation/backup and all that.
    XML isn't better than databases, and it's not perfect for everything, but there are a lot of situations where it has definate advantages.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Posts
    149
    Rep Power
    13

    Uses?


    I'm in exactly the same boat as jeremiah. I do most of my development using PHP4 and MySQL databases. For previous projects I've done, like customer and membership databases, using XML probably wouldn't have been a good idea since there are hundreds or thousands of records that need to be saved.

    But a buddy of mine gave me an idea. I guess a game that he plays online (DAoC) exports game statistics to an XML data file so they can be automatically imported into a webpage. Sounds like a good idea, but what else could I use XML for?

    I had an idea of using XML to structure my entire personal homepage. Structure in the sense that it would define the different sections fo my site, and define things like color schemes for each section, and then my content for those pages would likely come from a MySQL database anyway, unless it'd be easier to have the actual site content in XML as well. Only thing is, I wonder whether this is a practical use of XML?

    Unfortunately, besides the idea of exporting game stats, I don't grasp the concept of what XML is used for. Sharing data, yeah.. like the game stats, is a good, practical application. But what else can I do with it? What would most people use XML for, or would they?

    - coredumped.
  8. #5
  9. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Well, uses...
    Microsoft is using XML for all it's Office files, supposedly.
    SVG (scalable vector graphics), is XML.
    A number of university libraries that have online catalogs use XML to store the data.
    If you find yourself serializing objects and storing them in a database, XML would probably be helpful. Then you could search a group of related objects without having load/unserialize each one first.
    Any time you have a collection or heirarchy of data that isn't tied to a complex system of relationships. Newsfeeds, product lists, playlists, stuff like that.
    XML is just a file format, MySQL could probably be rewritten to use XML to store its data on disk (it would probably be slower, though).
    I hope this helps...
  10. #6
  11. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Posts
    3
    Rep Power
    0
    I'm still having a hard time thinking of practical applications for using XML. It's touted as the future of the internet, information sharing, etc.. I don't see it. In order for XML to be useful for information sharing you need a naming convention. Otherwise you have to study the XML file (which may be complicated) and come up with the appropriate translation to integrate it into your database (be it XML or other) or display it. As such XML by itself isn't any more useful (practically) than any other file format. If you receive information in any format and need it in another you have to convert it.

    XML sounds to me similar to the idea of TeX: to separate the information from the formatting. At work we use LaTeX which defines a set of macros for predefined document classes (such as a book, article, report). It's useful because it separates information from formatting and it defines a set of macros (tags) to use.

    Unless there's some sort of naming convention setup I don't see how XML is that useful. And even if there are conventions for different types of information I don't see why you just wouldn't use a database instead. So in short I'm having a real hard time seeing the practical value in XML. It sounds neat on paper .
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Posts
    149
    Rep Power
    13
    I've been thinking about it quite a bit, and I could see how for things like keeping the information for your website, for example, seperate from the formatting... it makes sense from a design perspective... instead of updating your HTML every time you update the content, you just update the XML document and it changes automatically... but even then, you can implement that using PHP and MySQL anyway, and probably a LOT easier too.

    Like I said before, in a previous post, if I could user XML to design the layout of the site, and not the layout as in how it appears on the screen, but the layout as in how the site is structured, whct pages are subpages of others, etc. then I could potentially see a use for XML in that sense, but I look at the database systems I've written, and can't see any way how I would ever want to use XML on them.

    - coredumped.
  14. #8
  15. No Profile Picture
    Moderator =(8^(|)
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Feb 2002
    Location
    Sacramento, CA
    Posts
    1,710
    Rep Power
    14
    Well, as far as sharing information goes, it would be rather inconvenient for me to email you my database because I wanted to show you something =) Same goes if my application uses PostgreSQL and yours use MySQL. I can't just give you the data.
    As for naming conventions, there are a bunch of them. I can't remember specifics, but one's something like EDI, and I think it's used for bibliographical information. That's the DTDs are for, and a lot of work has gone into developing robust and mature DTDs for specific applications.
    Really, for most of the stuff I do, and most of the stuff you guys probably do, xml doesn't add a lot of value. The only difference would be that you no longer need a database engine to organize your data. It's all in the file.
  16. #9
  17. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Posts
    3
    Rep Power
    0
    I've had XML on the brain lately. I don't have all my thoughts organized yet but I've come up with some good uses for XML.

    XML is a good option when a database server isn't available or guaranteed. A good example would be address books (like Netscape's), the mbox mail format could easily be modified to use XML (although it's so straight-forward now it wouldn't offer any tangible benefits I can think of). Basically applications on personal PCs which store information in a file.

    Another great use of XML would be to encapsulate comments/documentation and php code in a single XML document. Then you could write translations to "format" the documentation into PDFs, HTML, man pages, etc.. We do something similar at work with our source code, except that the file format isn't XML. This makes documentation more manageable and since the php files aren't run through a compiler (and so dependencies aren't a concern) it makes for an elegant solution. Then you also create a very simple translation to take all the code elements and stick them in the appropriate php file.

    But, it doesn't make sense to me to take existing database content and stick it in a XML file. For most database-driven websites moving to storing data in XML files doesn't make sense. The only use for XML in this case would be to offer exported data in XML. Say for instance you have, like me, an online address book and want to offer some way to export/import data to it. XML might be a good candidate.

    But this brings me back to a previous comment that XML isn't useful (including DTDs) unless there is an element naming standard for the information. If there's not then a comma separated file makes more sense. Because at least then you know what each tuple (row) contains and can quickly whip up a script to "translate" it to some other format (or store it in a database).
  18. #10
  19. No Profile Picture
    Shrill Digital God
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2001
    Location
    Raleigh, NC
    Posts
    64
    Rep Power
    14
    I like to use XML for sharing purposes and not as a replacement for a database. More often than not I'm querying MySQL and converting to XML for use in other applications or for web services.
    I'm not impatient, I just have a low tolerance for boredom.
  20. #11
  21. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    24
    How I use XML...
    I am a member of an orienteering club in the UK, and for them I do their web site. Now, one of our events could have 140+ competitors or as little as 16. Each event is not linked to others, though there are leagues, but we don't do the league tables. Each event is essentially it's own microcosm. The courses range from 3 to 10+ and the details of these change at every event. Some events are held annually on the same day, such as boxing day. Added to this, the computerised finish is usually in a field, then whoever does the results has to get them online or to me later that day.

    The situation is a complicated one. So, the database design was looking overcomplicated, and could essentially grow massive over time as 20+ events every year with changing competitors would make tables very big after a while. If we did one major event the database could have 600+ competitors added in one go... and to search through all these for an event with only 16 people is time wasting. Plus, adding 600+ people without an actual SQL script for bulk loading would take serious time. The solution was XML, a system whereby each set of event data was seperate from the others and could be easily understood so that anyone could turn a simple results list into an XML file.

    The resulting file:

    http://www.northern-navigators.co.uk...bewi2002cc.xml

    and the output using PHP to translate the XML:

    http://cgi.friesian.free-online.co.u...bewi2002cc.xml

    Better still though, with a mobile phone and IIS/PHP installed on the laptop I can FTP the actual XML file from the finish and get the results online before leaving the forest or moorland. Doing that with MySQL would have proved much more complicated.
  22. #12
  23. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2002
    Posts
    13
    Rep Power
    0
    I used to built php pages with PHP_LIB TEMPLATES.
    It is a nice method for separating content and presentation.

    Yo have a template that looks like this:

    Code:
    <title>{TITLE}</TITLE>
    </head>
    <body>
    <a href="{PHP_SELF}">home</a> 
    <a href="{PHP_SELF}?action=login">log-in</a>

    and your functions will fill in the variables:

    PHP Code:
    $t->set_var("TITLE",$title);
    $t->set_var("PHP_SELF",$PHP_SELF); 
    Now I'm using XML and XSLT for two reasons:
    1. The XSL Templates will also work with other languages (JAVA,..)
    2. You can put if-then statment and other cool stuff inside the template making your code cleaner.

    I still use a database. I just put the results in an virtual xml file:

    PHP Code:
    $xmlstring = "<?xml version=\"1.0\"?>
            <main>
              <TITLE>
    $action</TITLE>
              <PHP_SELF>
    $PHP_SELF</PHP_SELF>
    </main>
         "
    ;
         
    $xslstring join(''file('./templates/main.xsl'));

    // call the XSLT processor
    $xsltproc xslt_create();
    xslt_process($xslstring$xmlstring$result);
        
    // output the result
    echo $result;
    Last edited by petrik; July 15th, 2002 at 12:46 PM.
  24. #13
  25. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Posts
    17
    Rep Power
    0
    Like petrik showed, you could have a database and XML working together to make the data useable to everybody, but still use a database for the SQL features.

    XML is most useful for sharing data across other websites. For instance if I made a list of tutorials in HTML, and somebody wanted to have that list on their site, I wouldn't tell them to strip out all the XML and format it their self. It would be much easier for them to use XML because it can be used on any platform, on any language.

    Also, as jerimiah stated, you could use XML when you dont have an enviorment with a dynamic language, but you still wanted to manage your data easily.

IMN logo majestic logo threadwatch logo seochat tools logo