views:

196

answers:

6

Hi Everyone,

From time to time, I see web pages whose content is solely written in XML (not HTML or XHTML). These pages usually have some style sheets (either XSLT or CSS) attached to them which makes them look like any other ordinary web page.

My question is, what are the advantages of such an approach (if any), and why would anyone choose to work this way?

EDIT: If this is a good thing, why is it not widespread?

EDIT 2: Thanks everyone for the great responses. They really enlightened me. I also found this question whose content is also related.

+6  A: 

It's easier to generate it programmatically and reuse it for other purposes than displaying as webpage.


Update:

EDIT: If this is a good thing, why is it not widespread?

Not everyone needs to generate it programmatically or reuse it for other purposes than displaying as webpage. It's then easier to use plain HTML.

BalusC
+1  A: 

Those pages use XSLT to get rendered on the client side. Not every browser (especially older ones) supports rendering XML + XSLT. XML can however be used server-side as template and get transformed to HTML by the application running on the server. I personally don't see any advantages to this approach.

halfdan
There were also pages which used XML with CSS. What is your opinion about those ones?
Venemo
Pretty much the same: If the browser supports rendering XML + CSS this approach is nice for static pages. You always have to rely on the client browsers ability to render your page. You have to decide if you can live with this caveat.
halfdan
@halfdan, is there a list somewhere about which browsers support it?
Venemo
+2  A: 

One possible advantage would be for use of the data of the page in something other than a web browser; that would (presumably) be easier to do if a page's content were well-formed XML. Of course in theory a well-formed, semantic XHTML page should be nearly as able to be parsed, as well.

It can also be easier to generate XML instead of XHTML, depending on the data source.

Andrew Barber
+2  A: 

When you are getting XML data in to your system, and you are supposed to present this XML data then it is much easier to write some XSLT for that XML instead of parsing it using some sort of parser and then presenting the data.

That can be a valid point for using XML instead of XHTML or HTML

Update To answer your question on why this is not widespread, is because XSTL is tedious and hard to work with. Specifically XPath, which can be for some people quite difficult to use.

Shervin
@Shervin, very good points. How about the ones using CSS instead of XSLT?
Venemo
The difficulty of writing XSLT and using XPath is, to put it mildly, overstated. It's difficult to *learn*, because it's generally not taught very well, but it's not at all hard to work with.
Robert Rossney
Absolutely agree with Robert. XSLT is less difficult than many programming languages.
Rob
+1  A: 

There are a lot more web pages that are written solely in XML than you know. You're only seeing the ones that do the XSLT transformation on the client side. Server-side transformation of XML is not at all unusual, because there's a plethora of things that produce data in XML, and transforming XML to HTML in XSLT is straightforward. You'll never know this is happening if you just look at the HTML, which bears no signs of having been generated via XSLT.

Robert Rossney
A: 

Personally, I don't understand it either though one of the biggest problems is support in IE. I created a skeleton ecommerce site serving XML, transformed by XSLT and styled using CSS. I sorely missed the ability to use XLink and other wonderful XML features. It's also nice to be able to tag the data for what it is. I used a 'menu' tag for the restaurant menus. 'price' tags for prices and so on. If a user clicked on a link to change menus, all I had to do was send the name of the item, the price and the description instead of the complete page. iirc, a 4K or more HTML menu page was only 200 bytes of sent data.

As far as the "one error makes everything crash in XML" type comments, the same is true of any programming language so proper coding should be no bother for programmers and careful HTML/CSS types.

Before anyone says that what I did was actually XHTML...no. I served XML. I did call up XHTML namespaces when needed for links, images and HTML type things but only when necessary.

Rob
Nince answer, thank you!
Venemo