Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Difference between a parser and xsl

 
Ram Korutla
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Phani
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24211
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic