ルート ノードにのみ xmlns 属性を追加したいのですが、名前空間をルート要素に追加すると、後続のすべての子要素も同じ xmlns 属性を取得します。xmlns 属性を単一のノードに追加し、その子ノードには追加しないようにするにはどうすればよいですか? コード:
public String toXml() {
Document document = DocumentHelper.createDocument();
Element documentRoot = document.addElement("ResponseMessage");
documentRoot.addNamespace("",getXmlNamespace())
.addAttribute("xmlns:xsi", getXmlNamespaceSchemaInstance())
.addAttribute("xsi:schemaLocation", getXmlSchemaLocation())
.addAttribute("id", super.getId());
Element header = documentRoot.addElement("Header");
buildHeader(header);
Element body = documentRoot.addElement("Body");
buildProperties(body);
body.addElement("StatusMessage").addText(this.getStatusMessage().getMessage());
return document.asXML();
}