Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 334
  • Last Modified:

How to format an xml document so that it displays nicely in a JTextPane

I have an application that generates XML documents, but I want to display the XML documents in a nice fashion (in an HTML page), and then put it in a JTextPane.  How can I do this?
0
bjg
Asked:
bjg
1 Solution
 
rporazilCommented:
How do you represent XML document? Is this a String for you? Or do you use any other representation?
0
 
dorothy2Commented:
You can either (1) traverse the DOM in your Java code to do what you want, or (2) use an XSLT processor. An XSLT processor takes a source xml document, and an XSL stylesheet, and generates an output html, text file or xml file. What parser are you using now? Apache has an XSLT processor called Xalan which should help you get started. Writing the program which takes three arguments (source xml, XSL stylesheet, and output file name) and performs the transformation is trivial. Writing the XSL stylesheet is a little tricky because you have to learn XSL (extensible stylesheet language), but if what you want to do is fairly straightforward it shouldn't be too bad.

You should be able to use Xalan no matter what parser you are using, but it may be a little easier to get up the learning curve if you are already used to Xerces.

Good luck,

Dorothy
0
 
alireza_afsharCommented:
Use xsl, how, I teach you the basics, I suppose you use jsp for generating html with the xsl style sheet, and so your servlet engine is "Allair JRun", ok,1'st lets see the JSP file that have embedded xml for a user to login with entering username and password:

login.jsp :
<%@ taglib uri="jruntags" prefix="jrun" %>
<jrun:xslt xsl="go.xsl">
 <Client>
  <name></name>
  <password></password>
 </Client>
</jrun:xslt>
_______________________________________________________
login.xsl:
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output method="html" version="4.0" indent="yes"/>

<xsl:template match="/">
<html>
<head>
<title>Login </title>
</head>
<body>
<form action="login.jsp" method="post">
 <xsl:apply-templates select="Client"/>

 <input style="color: rgb(255,255,255); background-color: rgb(0,0,255)" type="submit" value="Sign in" align="middle"/>
</form>
</body>
</html>
</xsl:template>

<xsl:template match="Client">
<xsl:text>User Name :</xsl:text>
<input type="text" name="name" value="{normalize-space(name)}"/>

<xsl:text>Password :</xsl:text>
<input type="Password" name="password" value="{normalize-space(password)}"/>

</xsl:template>
</xsl:stylesheet>
_______________________________________________________

But if you have iterative xml data, you should use recursive xsl, that is a little hard, but if you say obviously what is your problem, i will solve it, ;)
good luck
robin
0
 
MoondancerCommented:
This question appears to have been abandoned. In fact, I will include links to ALL your open questions below:
 
Your options are:
1.  Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3.  Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4.  Delete the question. Again, you must tell the other participants why you wish to do this.
 
For special handling needs, please post a zero point question in the link below, include the question QID/link.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click this Help Desk link for Member Guidelines, Member Agreement and the Question/Answer process:  Click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues.
http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp
 

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:
 
Please leave any comments regarding this question here on closing recommendations if this item remains inactive another three days.
 
Thank you everyone.
 
Open Qs:

http://www.experts-exchange.com/jsp/qShow.jsp?qid=11466298
http://www.experts-exchange.com/jsp/qShow.jsp?qid=11480198
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20081509
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20101105
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20107120
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20119910
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20137332
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20165238
http://www.experts-exchange.com/jsp/qShow.jsp?qid=20269609
 
 
Moondancer
Moderator @ Experts Exchange
 
P.S.  For year 2000 question, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
 
 
0
 
NetminderCommented:
Force-accepted by
Netminder
CS Moderator
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now