I use XML two ways: to feed products into ecommerce sites and company information into directory sites. Of course I use XSL to achieve the layout and CSS for the styling, but I find it is an easy way to create dynamic content pages.
When I fetch information from a database (MySql is all I've used so far unfortunately) I typically just take the data and plug it directly into the dynamically generated html. Is there an advantage to using XML as a mediator in this process? Is it easier to do when working with non-MySql databases? Is it easier to deal with the data in XML format?
In most places you find XML it's not strictly the best choice - it adds significant bloat to what is usually a fixed well defined format. You should only be using it where there is a reasonable expectation that your data structures will change and be flexible.
Sending back a success response or a item number as an XML statement is absolute overkill - direct text is almost certainly a better option.
We use XML as an exchange and transfer medium. We use it in a number of ways; from C++ programs exchanging data across an API, to Web servers sending data to clients.
Yeah, it's bloaty, but you pay a price for a common exchange format with built-in parsers in every language on Earth. Go ahead and write your own, but you'll need to write and test your own parser. Have fun. You can use JSON, but that's just as bloaty, and quite awkward.
BTW: I'm in the process of developing a new Web service that will send XML to clients. I've decided that the XML will be in the form of XHTML. This is a bit wordier than writing custom XML, but has the significant advantage of being able to be placed directly into a Web page with no parsing.
- it's a polite way to package up data shared with 3rd parties (like an API)
- RSS, obviously
- occasionally I'll use an XML file to store config settings for an application
- serializing complex hierarchical data, in a way that can be saved and shared (for instance, playlists or saved game settings)
- data that is made accessible in multiple formats, since I can create the DAL once and get XSLT to do the transformation
- platforms with multiple skins that are being rendered in HTML
|are there databases that will directly give you xml? |
Yes -- Microsoft SQL Server can deliver XML right out of a SQL command. Do a search for "SQL FOR XML"; all the SQL queries end with "FOR XML something". It can also do fast paced searches for XML stored in databases.
MySQL 5.1 has XML features built in too
So what I am hearing is that XML is good for transfering data between applications and 3rd parties but is not so good for local data manipulation. Would you say this is a correct summary?
Thanks for all your replies,
It's less efficient than binary forms, as far as data content and data size.
However, it comes with an enormous arsenal of tools and language support. It affords incredible flexibility and stability.
In many cases, how long it takes you write something, test it and support it need to be factored into the calculation.
For example: If it takes you five minutes to write a routine that parses XML, even if the XML will be transported locally, and you don't worry about testing, and it takes you two days to develop a binary transfer API, and another two days to test it; all for transfers of 64 bytes of data, then which do you think is more efficient?
2days? I spent about a month working on a java parser once 0.o it was a pain in the ***! That's the project I mentioned in my first post - after it was all said and done I looked over on my bookshelf and saw my XML book... I h8 myself :( lol.
I'm considering going back and changing it. But I may just wait until Version 2 of the program - I'm not sure yet as the program isn't complete yet. I've been too lazy to work on it though - its a personal side project.