Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2001-08-08
5
Medium Priority
?
330 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 800 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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

722 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