0

String to be displayed in XML format on the screen

asked 2011-05-04 05:30:25 +0800

subbuaub gravatar image subbuaub
48

Hi all,

Any suggestion on how to display a string(xml content) as XML on the screen?
Any ZK component to format it ( to make it readable) ?
Currently I use textbox to display the string (xml content) that is not formatted.

regards
Subbu

delete flag offensive retag edit

3 Replies

Sort by ยป oldest newest

answered 2011-05-04 08:09:50 +0800

subbuaub gravatar image subbuaub
48

Found solution..
used DOM to get formatted XML.

Code is below,

public static String formatStringToXml(String input)
{
input = input.replaceAll("\t", "");
input = input.replaceAll("\r\n", "");
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();

DocumentBuilder builder;
try
{
builder = factory.newDocumentBuilder();

// Use String reader
Document document = builder.parse(new InputSource(new StringReader(input)));

TransformerFactory tranFactory = TransformerFactory.newInstance();
Transformer aTransformer = tranFactory.newTransformer();
aTransformer.setOutputProperty(OutputKeys.INDENT, "yes");
aTransformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
Source src = new DOMSource(document);
StreamResult result = new StreamResult(new StringWriter());
aTransformer.transform(src, result);
return result.getWriter().toString();
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
return null;
}
}

link publish delete flag offensive edit

answered 2011-05-04 15:10:29 +0800

mjablonski gravatar image mjablonski
1284 3 5
http://www.jease.org/

Hi,

another option might be to use zk-codemirror which also brings syntax-highlighting:

Demo: http://jease.org/codemirror/
Download: http://code.google.com/p/zk-codemirror/

Cheers, Maik

link publish delete flag offensive edit

answered 2011-05-05 06:25:32 +0800

subbuaub gravatar image subbuaub
48

Thanks Maik. Good look and feel.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-05-04 05:30:25 +0800

Seen: 269 times

Last updated: May 05 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More