protected void writeDocumentImpl(Writer w, String dtdName, String encoding) throws IOException { try { if (encoding != null) { w.write("<?xml version=\"1.0\" encoding=\"" + encoding + "\"?>\n"); } else { w.write("<?xml version=\"1.0\" encoding=\"ISO-8859-1\"?>\n"); } if (dtdName != null) { w.write("<!DOCTYPE app SYSTEM \"" + dtdName + "\">\n"); } write(w, ""); } finally { w.close(); } }
protected void write(Writer writer, String prefix) throws IOException { if (m_name == null) { this.writeEncoded(writer, m_contents); return; } writer.write(prefix + '<'); writer.write(m_name); if (!m_attributeMap.isEmpty()) { for (String key : m_attributeNames) { String value = getAttributeInternal(key); if (value != null) { writer.write(' '); writer.write(key); writer.write('='); writer.write('"'); this.writeEncoded(writer, value); writer.write('"'); } } } if (!m_children.isEmpty()) { writer.write('>'); writer.write("\n"); Iterator<?> en = this.getChildren().iterator(); while (en.hasNext()) { SimpleXmlElement child = (SimpleXmlElement) en.next(); child.write(writer, prefix + " "); } writer.write(prefix + '<'); writer.write('/'); writer.write(m_name); writer.write('>'); writer.write("\n"); } else if ((m_contents != null) && (m_contents.length() > 0)) { writer.write('>'); this.writeEncoded(writer, m_contents); writer.write('<'); writer.write('/'); writer.write(m_name); writer.write('>'); writer.write("\n"); } else { // this.children.isEmpty() writer.write('/'); writer.write('>'); writer.write("\n"); } }