Element root = (Element) doc.createElement("username");
    root.setAttribute("xdbns","111:222");
    doc.appendChild(root);
你弄反了^_^
<?xml version="1.0" encoding="UTF-8" ?>
这个不好去掉,应该是newDocument()就有了,而newDocument()没有参数,如果一定要去的话就把它读进一个文件里去操作吧