पर प्रिंटिंग मैंने कुछ कोड बनाया जो एक्सएमएल के लिए एक नक्शा लिखता है। ऐसा लगता है कि यह काम कर रहा है लेकिन फ़ाइल को कोई नई लाइन के साथ मुद्रित किया गया है। तो किसी भी एक्सएमएल संपादक में केवल एक पंक्ति पर। मैं इसे प्रत्येक बच्चे के लिए एक नई लाइन पर कैसे प्रिंट कर सकता हूं?एक्सएमएल बनाना केवल एक पंक्ति
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.newDocument();
Element vdata = doc.createElement("vouchdata");
doc.appendChild(vdata);
for (Entry<String, String> entry : vouchMap.entrySet()) {
Element udata = doc.createElement("vouch");
Attr vouchee = doc.createAttribute("name");
vouchee.setValue(entry.getKey());
udata.setAttributeNode(vouchee);
Attr voucher = doc.createAttribute("vouchedBy");
voucher.setValue(entry.getValue());
udata.setAttributeNode(voucher);
vdata.appendChild(udata);
}
// write the content into xml file
TransformerFactory transformerFactory = TransformerFactory.newInstance();
Transformer transformer = transformerFactory.newTransformer();
DOMSource source = new DOMSource(doc);
StreamResult result = new StreamResult(new File("vouchdata.xml"));
// Output to console for testing
// StreamResult result = new StreamResult(System.out);
transformer.transform(source, result);
देखें http://stackoverflow.com/questions/1264849/pretty-printing-output-from-javax-xml-transform -transformer-with-only-standard-j –