Forum Moderators: open

Message Too Old, No Replies

Is XML right for this job?

I'm trying to figure out if I can use XML to store a small amount of data.

         

bernk

8:39 am on Sep 13, 2007 (gmt 0)

10+ Year Member



I'm working on my personal site at the moment and trying to figure out the best way to go about maintaining my work portfolio.

I was thinking of having an XML file something like this:


<projects>
<project>
<title>Project One</title>
<type>brand</type>
<description>Project description blah blah blah</description>
<slides>
<slide>
<image>images/slide1.jpg</image>
<caption>some caption text</caption>
</slide>
<slides>
<links>
<link url="http://example.com" title="Project One" />
</links>
</project>
</projects>

Does this make sense at all? Would I be able to access each project similarly to a MySQL database? I would never have more than 50 projects or so and think this would be easier to maintain.

Is it possible to to example build an array of only the projects whose type is "brand" or "web"?

If this all sounds ridiculous, it's because I'm new to this. I've never used XML with PHP.

[edited by: jatar_k at 1:53 pm (utc) on Sep. 26, 2007]
[edit reason] please use example.com [/edit]

vincevincevince

9:05 am on Sep 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My first thought is 'no'.

Marshall

9:51 am on Sep 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



My first thought is 'no'.

IMHO, it all depends how you plan on using it. If you are creating static pages, then I agree with Vince. However, if you are creating dynamic pages, maybe (I know, no help). If it is truly dynamic where you want to call variables, I would suggest a database: MS Access or MySQL.

I use XML on a directory site of mine very effectively with page content being generated dynamically. Each listing, or in your case project, feeds different informaton to different pages: a category page, listings by country page, listings by states page, etc, which you can do with a database. But in this instance, I found it easier than dealing with databases especially since none of the information is confidential and in need of being secured. Granted, my file is about 8,000 lines long at this point, but the pages load very quickly using an asp call up.

In the end, either method can provide you dyanmic information and is generally easy to work with depending on your scripting level. Again, IMHO, it comes down to what you are comfortable with. But as I stated in the beginning, if you are creating static pages, I say no.

Marshall

bernk

10:11 am on Sep 13, 2007 (gmt 0)

10+ Year Member



Right.

I am using dynamic pages. Basically, I want to have one projects.xml file like the one above containing all my projects (no more than 50), with all the information for each project.

Then I want to have dynamic PHP pages like brand.php and web.php which will grab all of the brand or web projects out of the XML file, and all the associated information.

To be honest, I'm not much of a programmer...I would normally do this using MySQL but I thought I'd give XML a try because I like how I can structure the data. I like how I can have slide "containers" which have the image URL and a caption all nicely nested. I don't really know how to do something similar in MySQL so I guess that's my issue.

...perhaps I should take this to the MySQL forum.

Marshall

10:27 am on Sep 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



bernk,

I use asp to call what I want and am not too knowledgeable in php. You may want to check w3c's [w3schools.com] tutorial site on using php to call XML data, though I am sure there are many experienced people who can help you here. I suggest posting under the PHP Scripting [webmasterworld.com] forum if W3c cannot help you.

Marshall

cmarshall

10:30 am on Sep 13, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My outlook is this:

If it is data that will be used by more than one set of code, especially ones that you can't anticipate, then:

Yes.

If it is data that will be used exclusively in a closed system, with a pretty well-known application, then:

No.

If it is data that you would like directly sent to the browser (or other sites) in a fashion that they can interpret (such as RSS [w3schools.com], JSON [json.org] or CSV [en.wikipedia.org]), then:

Yes.

Basically, XML is a medium of transfer, not really of storage. It certainly can be used as a storage medium (there's even a language [w3schools.com] for it), but you usually set up an XML schema [w3schools.com] for data when you shake the magic 8-Ball [en.wikipedia.org], and it comes up "Cannot Predict Now." The idea is to have some flexibility.

I never write XML without writing a schema, so there's usually a fair bit of work involved.

One thing about XML, is that it comes with a great many tools built-in to many languages, such as PHP's Parser [us2.php.net] and DOM [us3.php.net] tools.

If you want to use these, which can be very powerful indeed, then it may be worth it.

It probably isn't worth it for this particular project, but think of this thread as your "XML heuristic" for determining whether you need XML for something.

httpwebwitch

1:33 am on Sep 26, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



go for it! Lately more and more I've been enjoying putting seemingly insignificant chunks of data into XML. They're easier to manipulate and transform (w/ XSLT) into anything imaginable, and XPATH selectors make grabbing individual elements a breeze.

Even when the dataset is huge, I'll dump it into SQL and make a DAL to grab tiny portions - as XML.

ssamuel

4:16 pm on Sep 27, 2007 (gmt 0)

10+ Year Member



Absolutely... no reason not to use XML. I disagree with cmarshall, there's nothing in XML that says it has to or even should be used for transfer and not storage.

Consider:

1. XML is just as easy to query (easier, if you ask some) than MySQL. With MySQL, you create a connection then run SQL. With XML, you load your document into a DOM then run XPath. Both yield exactly the same thing.

2. The XML is easier to edit than the MySQL data. Any text editor will make it editor, as opposed to composing and running SQL.

3. You're just as structured if you actually define a schema for your document. Any half-decent XML editor will gladly validate against your schema.

4. There's really no difference between MySQL and XML for purposes like this. MySQL comes with tools to import and export as XML. With a tiny bit of planning and patience, you can convert from one to the other seamlessly.

cmarshall

4:25 pm on Sep 27, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Absolutely... no reason not to use XML. I disagree with cmarshall, there's nothing in XML that says it has to or even should be used for transfer and not storage.

Consider:

1. XML is just as easy to query (easier, if you ask some) than MySQL. With MySQL, you create a connection then run SQL. With XML, you load your document into a DOM then run XPath. Both yield exactly the same thing.

2. The XML is easier to edit than the MySQL data. Any text editor will make it editor, as opposed to composing and running SQL.

3. You're just as structured if you actually define a schema for your document. Any half-decent XML editor will gladly validate against your schema.

4. There's really no difference between MySQL and XML for purposes like this. MySQL comes with tools to import and export as XML. With a tiny bit of planning and patience, you can convert from one to the other seamlessly.

You do realize that you didn't actually disagree with me, right? ;)

You get a heck of a lot more with *SQL than just storage. Indexing and searching are what it's really all about.

But I completely agree with you.

Welcome to WebmasterWorld!