File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes XML -vs- HTML or others Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML -vs- HTML or others" Watch "XML -vs- HTML or others" New topic

XML -vs- HTML or others

Ray Marsh
Ranch Hand

Joined: Jan 12, 2000
Posts: 458
What is the advantage of XML of other methods.
I'm green as can be in this arena so go easy on the answer.
Yes, Paul this a blatant attempt to win a free book!
However, This is a real question I've had. Not being familiar with web development and soon to be involved in it. It's good to learn the pros and cons fo different approaches.

Anxiety does not empty tomorrow of its sorrows, but only empties today of its strength. – Charles Spurgeon
Bill Pearce
Ranch Hand

Joined: Sep 19, 2000
Posts: 53

HTML and XML are really used for two different purposes, but basically HTML is concerned with *presentation* of information, not the informatin itself. XML is *data* only. Not just the data itself, the tags of XML describe what type of data is contained in the document. For example, if I sent you an HTML file with the following information about the weather:

How would you write code to automatically extract that data for your application? What if my HTML changes so that I no longer use HTML tables to display my data? In XML, I would send you a document something like this:

Now you can load up your XML parser and look for the <city> you are interested in, and extract the <temp>, to maybe display on your web site. If you were using XSL, you might process the whole document and transform it into HTML to make it look like you want. You might even transform it into WML for display on a WAP enabled phone or palm device.
So the quick answer is HTML does nothing more than format a web page for display. XML is data that describes itself. Some refer to it as "portable data".
See ya,
Ray Marsh
Ranch Hand

Joined: Jan 12, 2000
Posts: 458
Thanks... although the mechanics of it all still eludes me a bit.
If I want to display a web page, I can create a HTML file. How does XML fit. Does it replace HTML or is it used in conjuction or both or neither? I may be talking apples and oranges here. Let me know if I am.
Bill Pearce
Ranch Hand

Joined: Sep 19, 2000
Posts: 53
If you just want to display a web page, consider XML as a source of the *data* included in the web page. What you would need then, is a way to transform the XML document into HTML. This is where XSL comes in. In order to make the transformation, you need yet another file, an XSL stylesheet (as well as an XSLT processor like Xalan).
The stylesheet is a mixture of XML and HTML tags, and tells the processor how to format certain elements based on the tags surrounding them. For example, lets say you want to take the previous weather XML document and put it on your web page. Your XSL stylesheet might have tags like:

The above (which it just a portion of the actual stylesheet, tells the processor to make the information in the "name" tag bold and the value in the "temp" tag italic.
If you have Xalan installed correctly (have the jar in your CLASSPATH), all you have to do to convert XML to HTML using a stylesheet is (from a command line):
java org.apache.xalan.xslt.Process -in weather.xml -xsl style.xsl -out weatherPage.html
So this allows you to batch-process many XML documents, turning them into static web pages for use on your site. If you then want to totally change the way your site looks, design a new stylesheet, process the docs again, and you're done.
Or if you already have a servlet engine, you can write a simple servlet that calls the processor and dynamically applies a stylesheet based on some variable.
Hope I have not confused you further. You should be able to download Xalan from and run one of the simple examples.
Good luck,
Chuanshuang Bie

Joined: May 19, 2000
Posts: 11
Thanks, it is really helpful.
Ira Jain
Ranch Hand

Joined: Sep 06, 2000
Posts: 70
As Bill said XML is "data"specific whereas HTML is "presentation " specific . Being so,XML helps users to easily manipulate the file & search a particular text.It also helps the user in understanding the tags even if the user does not have knowledge of the language which was not possible with HTML.
Hope I helped to show how XML is better than HTML etc.

I agree. Here's the link:
subject: XML -vs- HTML or others
It's not a secret anymore!