Code example for StringWriter

Methods: flush, toString

0
	public static CharSequence loadXmlStandalone(File file) throws Exception {
		// Dom4j handles the full spattering of crazy entity stuff that mapnik xml 
		// uses.  We bring it throug a DOM4j Document which is wasteful but avoids 
		// subtle entity related problems I was having 
		// TODO: Spend more time digging into this 
		StringWriter out=new StringWriter((int)file.length() * 4);
		SAXReader saxReader=new SAXReader();
		Document doc=saxReader.read(file);
		XMLWriter xmlWriter=new XMLWriter(out);
		xmlWriter.write(doc);
		xmlWriter.flush();
		out.flush();
		 
		return out.toString();
		 
		/* The following is the JAXP way, which mysteriously totally botches entities that contain 
		 * embedded XML 
		StringWriter out=new StringWriter((int)file.length() * 4); 
		Transformer transformer=TransformerFactory.newInstance().newTransformer(); 
		XMLReader saxReader=XMLReaderFactory.createXMLReader();