Page 1 of 1

PHP, MySQL and XML

Posted: Fri Nov 14, 2003 7:33 am
by Nay
Hey,

I am going to start on my site again now - since I have found a new host. What a strange reason :lol:. Anyhow, I was reading on about XML and I want to use it. Anyhow, but XML to me is not the best way for managing a site, but managing the site's content. So I was going to go this way:

MySQL Table - News

Code: Select all

id   |   file
1 | xml/news/1.xml
and in the 1.xml

Code: Select all

<news>
   <date>12-11-2003</date>
   <title>site opened!</title>
   <content>
      my site is officially re-opened as of today.
   </content>
</news>
i don't see much of any difficulty now but as time goes and more and more files come in, deleting may not be as simple as deleting a row in mysql like before, but then i can make a control panel page. anyhow, my main question is that, if xml is used this way, is it really effective or shall i just stuck to mysql tables for everything?

-Nay

Posted: Fri Nov 14, 2003 8:37 am
by maniac9
I'm curious, if you're going to be using that system, why not just use the database?

I once built a site (although it was in ASP at the time) that's content was run completely from XML, and it worked exceptionally well. Each section of the site (each page) was in a separate xml file - ie. news.xml, links.xml, and so on...and they looked something like...

Code: Select all

<news>

  <newsItem>
    <newsTitle>Blah</newsTitle>
    <newsBody>.........</newsBody>
  </newsItem>

  <newsItem>
    <newsTitle>More Blah</newsTitle>
    <newsBody>.........</newsBody>
  </newsItem>

</news>
And that worked very easily with M$'s DOM, but I haven't messed that much with PHP's XML stuff, so...

Another idea would be to drop the database (and even php) completely and just use XSL. With that, it can be hosted on pretty much any server, with all the processing left to the client, but the client's have to be new. Or, take the middle road, and use XML/XSL, but have the server process the XSL and send plain HTML/XHTML to the client. With the middle road, you can keep older clients, but have a nice site backbone prepared if you ever want to go full-on XML.

Posted: Fri Nov 14, 2003 8:39 am
by twigletmac
Stick to the MySQL tables - it'll make it much easier to manage your data than having it in text files (which is what the XML effectively is). In the long run you may wish to extract this data from the database as XML and then style it using XSLT (which is lots of fun :)). Or you could start doing an RSS feed.

Mac

Posted: Fri Nov 14, 2003 9:16 am
by Nay
yeah, along the way i was thinking about that. i just realized i don't NEED to have xml files to generate an RSS feed.

so i got into something like:

Code: Select all

$rss = "";
$result = mysql_query("SELECT * FROM 'news' ORDER BY 'id' DESC LIMIT 7", $some_connection);
while($rows=mysql_fetch_array($result) {
// output
echo <<< END
<p>{$rows['title']}</p>
<p>{$rows['news']}</p>
<p>Posted by {$rows['user']} on {$rows['date']}</p>
END;
// add to RSS
$rss .= <<< RSS

<news>
   <title>{$rows['title']}</title>
   <date>{$rows['date']}</date>
   <poster>{$rows['user']}</poster>
   <content>
      {$rows['news']}
   </content>
</news>
RSS;
}
is that any better? :lol:

-Nay

Posted: Fri Nov 14, 2003 10:50 am
by devork
I am also confused to use xml or mysql to manage data
-Is xml with xslt really good for managing site contents?
-what are xml's good points to be used.?

Posted: Fri Nov 14, 2003 1:28 pm
by JPlush76
for your site I would agree with MAC.. stick to MYSQL

Storing XML content files would be handy if you were formatting your contents for certain browsers, screen sizes, mobile phones, pdas using a separate XSL Style Sheet for each version or if you wanted to exchange that data to other sites easily without having to format everything from the DB.

If the articles won't change, then having them in XML files makes more sense since you wont be using the overhead of DB connections everytime someone wants to read an article. Changing XML files is more labor intensive than just updating a table field.

If its just you workin on the site with no plans to expand to have content writers or outbound data I'd stick with the DB for now. just my 2 cents

Posted: Mon Feb 02, 2004 3:51 am
by evilcoder
I'm currently writing a Content Management System which will be designed for sites which get massive hits to news pages etc.

I thought of XML and Java. XML can be a selected component to make dynamic content static, decreasing the load on the database, however i then find myself with a large system resource problem with 100,000 people opening up the XML instead of using the database. Weigh up what you'd rather, load on your database or on the file?

Hmmnn, where was i going with that? ahh too tired.

Posted: Mon Feb 02, 2004 8:06 am
by timvw
Big problem with XML data storage: It's doesn't really map on a E-R model.
XML is like going back to hierarchical and network databases.

Just write a script that delivers the data, and then let the template generate the xml, html, wml (whatever you like) wrapping around that data.