Solved

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

Posted on 2001-08-08
5
321 Views
Last Modified: 2013-11-18
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
Comment
Question by:bjg
5 Comments
 

Expert Comment

by:rporazil
ID: 6364354
How do you represent XML document? Is this a String for you? Or do you use any other representation?
0
 
LVL 6

Accepted Solution

by:
dorothy2 earned 200 total points
ID: 6364561
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
 

Expert Comment

by:alireza_afshar
ID: 6365665
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
 
LVL 1

Expert Comment

by:Moondancer
ID: 6828901
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
 
LVL 5

Expert Comment

by:Netminder
ID: 6891401
Force-accepted by
Netminder
CS Moderator
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

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.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
numbers ascending pyramid 101 212
Java exception bubble up 2 21
Convert from a json string array to a Java object 3 51
restrict decimal places for double datatype 10 19
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question