version = root.getXMLVersion();
}
}
marshalRecord.startDocument(encoding, version);
}
XPathFragment rootFragment = buildRootFragment(object, descriptor, isXMLRoot, marshalRecord);
boolean shouldWriteTypeAttribute = shouldWriteTypeAttribute(object, descriptor, isXMLRoot);
String schemaLocation = getSchemaLocation();
String noNsSchemaLocation = getNoNamespaceSchemaLocation();
if (isXMLRoot) {
object = root.getObject();
if (root.getSchemaLocation() != null) {
schemaLocation = root.getSchemaLocation();
}
if (root.getNoNamespaceSchemaLocation() != null) {
noNsSchemaLocation = root.getNoNamespaceSchemaLocation();
}
marshalRecord.setLeafElementType(root.getSchemaType());
}
String xsiPrefix = null;
if ((null != getSchemaLocation()) || (null != getNoNamespaceSchemaLocation()) || shouldWriteTypeAttribute) {
xsiPrefix = nr.resolveNamespaceURI(XMLConstants.SCHEMA_INSTANCE_URL);
if (null == xsiPrefix) {
xsiPrefix = XMLConstants.SCHEMA_INSTANCE_PREFIX;
nr.put(XMLConstants.SCHEMA_INSTANCE_PREFIX, XMLConstants.SCHEMA_INSTANCE_URL);
}
}
TreeObjectBuilder treeObjectBuilder = null;
AbstractSession session = null;
if (descriptor != null) {
session = xmlContext.getSession(object);
treeObjectBuilder = (TreeObjectBuilder) descriptor.getObjectBuilder();
} else {
session = (AbstractSession) xmlContext.getSession(0);
}
marshalRecord.setSession(session);
if (null != rootFragment) {
marshalRecord.startPrefixMappings(nr);
if (!isXMLRoot && descriptor.getNamespaceResolver() == null && rootFragment.hasNamespace()) {
// throw an exception if the name has a : in it but the namespaceresolver is null
throw XMLMarshalException.namespaceResolverNotSpecified(rootFragment.getShortName());
}
marshalRecord.openStartElement(rootFragment, nr);
if (null != schemaLocation) {
marshalRecord.attribute(XMLConstants.SCHEMA_INSTANCE_URL, XMLConstants.SCHEMA_LOCATION, xsiPrefix + ":" + XMLConstants.SCHEMA_LOCATION, schemaLocation);
}