- 
        1. Re: How to easily display Indented XML filesslashfr Jan 15, 2009 4:46 PM (in response to slashfr)No Idea? 
- 
        2. Re: How to easily display Indented XML filesctomc Jan 15, 2009 6:49 PM (in response to slashfr)Maybe this will help: public static String getXML(Document document, boolean indent) { OutputFormat format; StringWriter stringOut; XML11Serializer serial; if (document.getOwnerDocument() == null) { format = new OutputFormat(org.apache.xml.serialize.Method.XML, null, true); } else { format = new OutputFormat(document.getOwnerDocument(), null, true); } format.setOmitXMLDeclaration(true); if (indent) { format.setIndent(2); format.setLineSeparator("\r\n"); } else { format.setIndent(0); format.setLineSeparator(""); } stringOut = new StringWriter(); serial = new XML11Serializer(stringOut, format); serial.setNamespaces(true); try { serial.serialize(document); return (stringOut.toString()); } catch (java.io.IOException ioe) { throw new RuntimeException("Strange error. IOException occurred where it cannot!", ioe); } }cheers, 
 tomaz
- 
        3. Re: How to easily display Indented XML filesjagin Jan 15, 2009 6:58 PM (in response to slashfr)... or using XSLT. Look here: Oliver's XSLT page 
- 
        4. Re: How to easily display Indented XML filesnicolas.bielza Jan 15, 2009 10:36 PM (in response to slashfr)Several approaches for indenting XML documents are discussed here. I'm using com.sun.org.apache.xml.internal.serialize.XMLSerializer and it works fine for me (although it's undocumented and non portable). 
- 
        5. Re: How to easily display Indented XML filesnicolas.bielza Jan 15, 2009 10:41 PM (in response to slashfr)I meant to say com.sun.org.apache.xml.internal.serialize.OutputFormat works fine for me ! public String format(Document document, int indent) throws IOException { OutputFormat format = new OutputFormat(document); format.setIndenting(true); format.setIndent(indent); StringWriter stringWriter = new StringWriter(); Writer output = new BufferedWriter( stringWriter ); XMLSerializer serializer = new XMLSerializer(output, format); serializer.serialize(document); return stringWriter.toString(); }
- 
        6. Re: How to easily display Indented XML filesedmentay Apr 27, 2011 11:39 PM (in response to slashfr)hi, 
 I had tried the solution above. but its did't work!! my xhtml page is,
 <h:outputFormat id="xmlout" value="#{configList.xmlDoc}" rendered="true" />
 backbean statement is,
 ByteArrayOutputStream output = new ByteArrayOutputStream();
 output.write(tempapp.getxmlbytes());
 
 byte b[] = output.toByteArray();
 
 db = dbf.newDocumentBuilder();
 
 InputSource is = new InputSource();
 String content = new String(b);
 is.setCharacterStream(new StringReader(content));
 this.selectedDocument = db.parse(is);
 return this.selectedDocument
 Please help!!
 Regards,
 Edmen
- 
        7. Re: How to easily display Indented XML filesserkan.s.eskici.online.nl May 3, 2011 2:44 AM (in response to slashfr)I've the same usecase and what I've done is the following: <s:formattedText value="embrace you string within a singlequote (shows the string as a <code>, cant use it on this wiki message) #{myBean.blobText}" escape="false" />Assuming that the XML blob is already saved with correct indenting in the database. 
 
     
     
     
     
    