Click to See Complete Forum and Search --> : Advatages to XML?
studbuckman
08-25-2005, 04:13 PM
I have done a little research on XML and find it combersome and somewhat confusing. I am lost as to the advantages of XML and its offshoots. Why is XML touted as being so powerful? What can be accomplished in XML that cannot be accomplised through a combination of HTML, CSS, PHP, and MySQL? Although XML may be able to eliminate the need to use all of these languages at once, I find that it is much easier to use the aformentioned languages as opposed to XML.
sheila
08-25-2005, 05:00 PM
I usually find it more useful to store my data as XML rather than in a relational database, mostly because it's very easy to edit but also because you can get 'added-value' just from the way it's structured. For example, I have an xml document that contains information about a series of geographical locations, here's a simplified extract:
<locations>
<location id="LOC1" type="continent">
<name>Europe</name>
<location id="LOC2" type="country">
<name>England</name>
<location id="LOC3" type="county">
<name>Dorset</name>
<location id="LOC4" type="settlement">
<name>Bridport</name>
</location>
<location id="LOC5" type="settlement">
<name>Burton Bradstock</name>
</location>
<location id="LOC6" type="settlement">
<name>Beaminster</name>
</location>
</location>
<location id="LOC7" type="county">
<name>Somerset</name>
<location id="LOC8" type="settlement">
<name>Yeovil</name>
</location>
</location>
</location>
</location>
</locations>
All it is (as seen above) is a list of locations and their names. But merely from their positions in relation to each other I can tell that Burton Bradstock is in Dorset, which is in England, which is in Europe. When I use a relational database, I needed a separate table just to record this information.
Another major advantage to using XML is being able to use XSLT templates. They're fantastically powerful. If you have the patience, I'm pretty sure that if you persevere with trying to understand XML you'll come to see why some of us are so keen on it. It's really not that difficult.
Charles
08-26-2005, 06:36 AM
The simple answer, XML is more machine readable than SGML and more human readable than CSV.
Richard Conyard
08-28-2005, 05:47 AM
I must admit it took me a long while to get XML, I couldn't see what all the buzz was about just an SGML subset. Looking back I think it's because most XML fan are really, really bad at saying what's good about it! So a few XML bits...
XML allows hierachical data. This is fantastic for category listings etc. Take the standard table structure - CategoryID, CategoryName, CategoryParentID - to bring the tree out nicely in a DB query would be a pain, multiple queries etc. With XML you can bring this stuff back instantly. (SQL Server fans can do both with FOR XML AUTO, ELEMENTS on the end of their query).
XML has really powerful search tools built in. XPath is really very powerful and easy to use. root/node[position() < 4] <-- select the top three nodes; root/node[value = "asdf" ] <-- pattern matched; there are far more, but it gives you an idea how easy they are.
XML has really powerful render tools. XSL rocks! There are a few problems I find with escaped chars, but the other benefits make up for it. It encourages a split between business logic and render logic, it's easy to follow, it promotes templating, it promotes well written code.
XML as the name suggests is extensible. Unlike a relational database where if 6 months down the line if you want a new field added you will have to update the table, all the queries, capture perhaps any null errors. XML, you just add the field.
There are plenty more, but that must be good for a start.