public class XmlWriter {
private Map<String, String> nsnames = new HashMap<String, String>();
- private Document doc;
+ public final Document doc;
private int nsser = 1;
public XmlWriter(Document doc) {
}
if(postbreak(out, el))
- out.indent(indent);
+ out.write('\n');
}
protected void text(ColumnWriter out, String s, int indent) throws IOException {
- out.write(s);
+ out.write(Misc.htmlq(s));
}
protected void text(ColumnWriter out, Text txt, int indent) throws IOException {
}
}
+ protected void doctype(ColumnWriter out, DocumentType dt) throws IOException {
+ out.write(String.format("<!DOCTYPE %s PUBLIC \"%s\" \"%s\">\n", dt.getName(), dt.getPublicId(), dt.getSystemId()));
+ }
+
public void write(Writer out) throws IOException {
findallnsnames();
ColumnWriter col = new ColumnWriter(out);
DocumentType t = doc.getDoctype();
if(t != null)
- out.write(String.format("<!DOCTYPE %s PUBLIC \"%s\" \"%s\">\n", t.getName(), t.getPublicId(), t.getSystemId()));
+ doctype(col, t);
node(col, doc.getDocumentElement(), 0);
}
write(w);
w.flush();
}
-
- public static void main(String[] args) throws Exception {
- Html barda = Html.xhtml11("Barda");
- barda.addcss("/slen.css", "Test");
- barda.insert("body", barda.el("h1", barda.text("Mast")));
- barda.finalise();
- XmlWriter w = new XmlWriter(barda.doc);
- w.setnsname(Html.ns, null);
- w.write(System.out);
- System.out.flush();
- }
}