-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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
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;
}
}
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
Asked: 2011-05-04 05:30:25 +0800
Seen: 269 times
Last updated: May 05 '11