XmlBlob cumulative = new XmlBlob();
Collection<XmlNamespace> namespaces = cumulative.getNamespaces();
StringWriter w = new StringWriter();
XmlWriter xw = new XmlWriter(w);
if (xmlBlob != null) {
cumulative.setLang(xmlBlob.getLang());
cumulative.setBase(xmlBlob.getBase());
namespaces.addAll(xmlBlob.getNamespaces());
w.write(xmlBlob.getBlob());
}
if (manifest != null) {
for (XmlNamespace ns : manifest.getNamespaceDecls()) {
XmlNamespace newNs = new XmlNamespace(ns.getAlias(), ns.getUri());
if (!namespaces.contains(newNs)) {
namespaces.add(newNs);
}
}
}
for (Extension ext : nonRepeatingExtensionMap.values()) {
ext.generate(xw, extProfile);
}
for (List<Extension> extList : repeatingExtensionMap.values()) {
xw.startRepeatingElement();
for (Extension ext : extList) {
ext.generate(xw, extProfile);
}
xw.endRepeatingElement();
}
cumulative.setBlob(w.toString());
return cumulative;
}