final String URI1 = "http://foo";
final String URI2 = "http://foo2";
final String URI3 = "http://foo3";
sw.writeStartDocument();
sw.writeStartElement(URI1, "root");
sw.writeNamespace("foo2", URI2);
sw.writeDefaultNamespace(URI3);
sw.writeStartElement(URI3, "leaf");
sw.writeAttribute(URI2, "ns-attr", "1");
sw.writeAttribute(null, "ns-attr", "2");