aspose file tools*
The moose likes XML and Related Technologies and the fly likes Which is the efficient way to convert XML to HTML?. 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 "Which is the efficient way to convert XML to HTML?." Watch "Which is the efficient way to convert XML to HTML?." New topic
Author

Which is the efficient way to convert XML to HTML?.

Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
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.


Regards,
Nik
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41508
    
  53
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.


Ping & DNS - my free Android networking tools app
Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
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.


Regards,
Nik
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41508
    
  53
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?
Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
Hi Ulf,

Originally posted by Ulf Dittmer:
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.I dont have an idea.Please let me know on this idea.

Regards,
Nik
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41508
    
  53
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.
Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
Hi Ulf,
It's the latter that is converting an XML file into a PHP file.Any suggestions on how to do this ulf?.


Regards,
Nik
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41508
    
  53
No, because I don't know what it means to convert an XML file into a PHP file.
Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
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.

2.Use PHP.

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.


Regards,
Nik
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41508
    
  53
To quote my first post
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.
Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
Hi Ulf,
I did not understand these

use of XML APIs and direct generation of HTML markup another one.

Please explain me.


Regards,
Nik
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41508
    
  53
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".
Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
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.

Regards,
Nik
[ January 22, 2008: Message edited by: Nik Arora ]
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41508
    
  53
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.
Nik Arora
Ranch Hand

Joined: Apr 26, 2007
Posts: 652
Thanks a lot ulf.



Regards,
Nik
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Which is the efficient way to convert XML to HTML?.