On Mon, 2003-10-27 at 20:40, Simon Fredriksson wrote: > I think I've missed something somewhere, but how do I use XML? > Everywhere, there are big hypes about XML. I could proably google quite > a bit on this, but could someone give me a hint on how to use it in, say > datahandling? Or to parse a website (like the php docs).
PHP docs are SGML as far as I can remember. I think XML is a subset of SGML. I would agree that XML in many cases has been hyped, but from a practical point of view it does also have a lot of merit. One of the examples I have found for it to work extremely well is on my MUD project (Multi User Dimension). For example let's say we have a player with the following stats: strength intelligence wisdom dexterity constitution We could define an XML document which stores this data in clear, concise, and human readable fashion such as the following: <player> <strength> 15 </strength> <intelligence> 19 </intelligence> <wisdom> 18 </wisdom> <dexterity> 14 </dexterity> <constitution> 10 </constitution> </player> This is a pretty simple format, the fields are self explanatory. Now one of the great advantages of XML is its flexibility. Let's say I now want to add support for a charisma field... well it's as simple as adding the field to the data, and if it doesn't exist assuming a default: <player> <strength> 15 </strength> <intelligence> 19 </intelligence> <wisdom> 18 </wisdom> <dexterity> 14 </dexterity> <charisma> 17 </charisma> <constitution> 10 </constitution> </player> In older data formats such as binary, to add such a field would generally require that version information be stored at the beginning of the document and then when the data is resaved it would be saved as the newer version. This caused problems with multiple versions in existence, whereas with XML since the fields don't necessarily need to have any kind of order, we don't need to keep track of version, only whether or not the field was included. The other alternative (if you had complete control over the data) was to convert it all to the new format which was generally a tedious job and required a fair amount of effort to ensure the validity of the new format. This is quite a trivialization of XML, but this is one of the main advantages I see for it. One could easily define a multitude of other formats that are just as flexible, but currently XML is well supported by the development community and so is probably the better choice. As with all things, your mileage may vary. HTH, Rob. -- .------------------------------------------------------------. | InterJinn Application Framework - http://www.interjinn.com | :------------------------------------------------------------: | An application and templating framework for PHP. Boasting | | a powerful, scalable system for accessing system services | | such as forms, properties, sessions, and caches. InterJinn | | also provides an extremely flexible architecture for | | creating re-usable components quickly and easily. | `------------------------------------------------------------' -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php