Solved

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

Posted on 2001-08-08
5
313 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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
WCAG audit tools 1 51
XML Paring  Error - Premature end of file. 7 55
Python Assistance 7 31
Re-position the objects 7 47
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…

708 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now