How do I add a PI or Comment before the root element?You must access the document content as a List. Either get the list and add content to its head, or set the list of content explicitly.doc.getContent().add(0, pi);
or
doc.setContent(listOfContent);
or
doc.setContent(listOfContent);
输出到开始部分?就是第二行!