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

    Join Date
    Mar 2001
    Location
    Ljubljana, Slovenia, Europe
    Posts
    29
    Rep Power
    0

    Database vs. XML


    I can't realy get to understand how could XML be useful to store data for a database-driven web site. Isn't data already described when properly put in the database. I read about how to use XML to store content, and than use XSLT to create XHTML (layout), and use CSS to apply design to XHTML layout. But what I didn't get is when I read "...and you store your XML data into a database". What is the purpose of storing XML marked content into a database?
    And when I think about dinamyc data driven web site, it seems illogical to use XML at all. If I want to do queries on my data it is best (I think) for the data to be in a database. For example: If I wanted to count how many articles were published on my site. This seems harder (and slower) to do without a database. It seems logical to use XML for exchanging data between different systems. But how could this benefit me at bulding non-static sites?

    Well this are some of my thoughts. Please make some comments and enlighten me. How shoud I use these techologies?
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Location
    UK
    Posts
    59
    Rep Power
    13
    My sentiments exactly. I also fail to understand the reasons behind it. I can see benefits of XML in the sense that you have an architectural, platform and database engine free means of describing your data. So in terms of portability it's excellent.

    However, when trying to understand it's benefit over a database on sites that don't need to share information is harder to understand.
    Torrent
    www.ski-info-online.com

    ...silently carving the soft deep powder...
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    London
    Posts
    4
    Rep Power
    0
    Well, the purpose of xml is to add structure to documents. If you have a database to populate an xml page, it will allow the user to interact with the xml dom, thus allowing the queryed arguments for sorting the page without reloading the page and pulling the content from mySQL, therefore saving resources as well.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    vancouver, bc
    Posts
    145
    Rep Power
    15
    Originally posted by Andrew-J2000
    Well, the purpose of xml is to add structure to documents. If you have a database to populate an xml page, it will allow the user to interact with the xml dom, thus allowing the queryed arguments for sorting the page without reloading the page and pulling the content from mySQL, therefore saving resources as well.
    Hi,

    can you provide an example or a link to an example that does that you just said?

    I'm still trying to 'understand' xml and an example of what you said would be perfect.

    thanks
    edwin
    I know nothing
  8. #5
  9. Contributing User
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Oct 2001
    Location
    New Zealand
    Posts
    1,774
    Rep Power
    24
    An example could be this:

    We have a program that uses a folder tree. The tree itself is organised within a database, the underlying filesystem is flat. So 'here>there>everywhere>file.jpg' exists at 'files>file.jpg' and not where it would appear to be. A PHP script queries the database to create an XML file representation of this folder tree. This XML file is easily parsed into a physical representation of a collapsing/expanding folder tree, that maintains the illusion. Because an XML file is being created it means that the file can be used by more than one application, which it is, without more database connections being made. It also means that a state can be saved so that when the page is reloaded the folder tree remains in the expanded state that it was left in. If a file/folder is added then the XML file is recreated, otherwise it is the same file that is used for subsequent uses.

    Another use for XML database interaction is to have two dimensions within a table. If some data is going to be static, instead of having a lookup table you can simply insert the data as a blob of XML that can parsed on retrieval, it may go against the RDB and data integrety concept but it makes things quicker and simpler, which is sometimes needed. For example, you could 'roll up' all the news from today into a single XML file and put in a database table with fields NEWS_DATE and NEWS_TEXT, then you would have a simple store but retain a degree of formatting possibility by inserting all the news as one blob of XML. It's tidier than having a massive number of entries for one day.
  10. #6
  11. 11
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Jul 2001
    Location
    Lynn, MA
    Posts
    4,635
    Rep Power
    82
    You can also use XML files in a way similar to what binky mentioned for a cheapo "version control" system in a CMS.

    When a document is edited, you create an XML version that represents the document at it's current state. You then store this XML version, along with an ID and a datetime string in a table. You can now list different versions of document over time and restore them if needed. Works pretty slick. If you're a perl person, check out XML::Simple and/or Data::Dumper to make this easy as pie.
  12. #7
  13. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Posts
    409
    Rep Power
    13

    Question


    So let me see if I've got the idea:

    1) I want to retrieve a list of titles of books.

    a. SELECT title, date FROM books;

    b. Then I use PHP to pull the data from my database and paste it to the client browser.

    2) But the user wants to also be able to sort this data by the date:

    a. SELECT title, date FROM books ORDER BY date;

    b. Then paste the data again using PHP

    If I were to use XML, I could transfer the duty of ordering the data completely to the client browser, thus bypassing the two steps in #2 above, completley? I would just use the data already retrieved in #1, and have XML tell the browser to do the sorting? If so, now that sounds like a good deal indeed.

    That would essentially cut the resource load on the server in half.
  14. #8
  15. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Location
    UK
    Posts
    59
    Rep Power
    13
    Originally posted by Hero Zzyzzx
    You can also use XML files in a way similar to what binky mentioned for a cheapo "version control" system in a CMS.

    When a document is edited, you create an XML version that represents the document at it's current state. You then store this XML version, along with an ID and a datetime string in a table. You can now list different versions of document over time and restore them if needed. Works pretty slick. If you're a perl person, check out XML::Simple and/or Data:umper to make this easy as pie.
    That's a neat idea. Thanks.
    Torrent
    www.ski-info-online.com

    ...silently carving the soft deep powder...

IMN logo majestic logo threadwatch logo seochat tools logo