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 Difference between a parser and xsl 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 "Difference between a parser and xsl" Watch "Difference between a parser and xsl" New topic

Difference between a parser and xsl

Ram Korutla
Ranch Hand

Joined: Dec 24, 2007
Posts: 80
Hi All
I am a bit new to the xml technologies.

I dont understand why an xsl should be required if we could access the nodes and the other xml related stuff using the parsers.

Please correct my below understanding:

An xsl can access and apply certain rules to the elements of xml without however actually modifying the content of the xml. With parsers we can actually add or delete the nodes of an xml.

Kindly let me know what exactly parsers and xsls are used for.

Many Thanks
Ernest Friedman-Hill
author and iconoclast

Joined: Jul 08, 2003
Posts: 24199

In theory, yes, anything you can do with XSL, you can do by programming in Java using the DOM tree produced by an XML parser. In theory, you don't need the parser, either; you could read the XML with a FileReader and pick through it yourself. Heck, you don't even need Java, do you: you could write the same program in 80x86 assembly language.

My point is that different tools operate at different levels, and have different strengths. Many simple querying and transformation tasks are clearer and easier to write in XSL.

[Jess in Action][AskingGoodQuestions]
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

Originally posted by Phani Sridhar:
With parsers we can actually add or delete the nodes of an xml.
Well, no, this is incorrect. The purpose of a parser is to convert an XML document -- a text file, usually -- into some internal form. A DOM parser converts a document into a Document object, a SAX parser converts it into a series of SAX events, and so on. No adding or deleting of nodes will occur here.

You can certainly take the Document object which is the output of the parser and add or delete nodes, though.

And just for completeness: a serializer is used to convert some internal form into an XML document.
I agree. Here's the link:
subject: Difference between a parser and xsl
It's not a secret anymore!