Hi Ranchers, I wanted to know which is the efficient way to convert XML to HTML?.I have downloaded a tool which does this and also i was going through the XSLT tutorial.Please let me know which is the best way to do it.
Efficient in which way - fast to program, fast to execute, least amount of code involved, ... ?
There generally is no single "best way", as it depends very much on your circumstances (about which we know nothing) which one that may be. XSLT would be be one way; use of XML APIs and direct generation of HTML markup another one.
Hi Ulf, Thanks for your reply. I wanted a information regarding conversion of XML to HTML and XML to PHP.I have not worked with PHP but want to know which is more useful whether converting XML to HTML or XML to PHP and the efficiency in executing.
HTML is a markup language for display, while PHP is a programming language for generating (mostly) HTML, so I'm not sure how converting XML into either of them can be compared. What does it mean to convert XML to PHP?
It means that converting an xml file into a php file but is it possible because php uses certain php tags to do it.
Now you seem to be talking about two different things: converting an XML file into a PHP file, and using PHP to convert XML into HTML. If it's the former, please elaborate what that means. If it's the latter, you might be better off posting this in a PHP forum.
Hi Ulf, Sorry for all the confusions.I will explain you what i need exactly.Please suggest me.I have lots of xml file. Now i want the data in xml file to be displayed in a well defined table structure and it should be a web page.
I got few suggestions from my friends i have mentioned them below.
1.Convert the XML file to HTML and display it.
So i was confused how to carry it forward.Please let me know on how to carry it forward i am really confused regarding which is the best way to do it.
There generally is no single "best way", as it depends very much on your circumstances (about which we know nothing) which one that may be.
XSLT would be be one way; use of XML APIs and direct generation of HTML markup another one.
If you're familiar with the Java XML APIs, that might be easier to start with. Using XSLT might be a cleaner approach that separates the transformation logic (and thus the markup) from the code doing the transformation.
I'm not too familiar with PHP, but I would imagine that it is possible to implement these two approaches using just about any language, including PHP.
You can use the Java API for XML processing -JAXP, and in particular its SAX API- to read the XML, and then write the HTML directly to a file using the java.io package. The http://faq.javaranch.com/java/XmlFaq links to some introductory material on this, e.g. the article titled "Introduction to DOM and SAX Parsing".
Hi Ulf, Thanks for the reply.Which will be better using XSLT or using java and SAX api?.Which will be more efficient in terms of execution?.And what are the advantages using XSLT or Java comparing to each other.
The question of which is better can't be answered in general. It much depends on the circumstances of the application, the software ecosystem it runs in, the developers' knowledge, etc. - all of which we know nothing about.
What do you mean by "efficient" - faster? If so, probably SAX, since there is a certain overhead in using XSLT. But XSLT has other benefits (like separating the logic from the markup being used) that may be more important.
But is raw performance really that important? If it is, you should definitely implement both, and then do speed tests in an environment that's comparable to the production system, using realistic data sets. But in my experience, raw performance numbers are rarely the deciding factor in design issues like this.