if (returnDescriptor == null) {
// Try to find a descriptor based on the schema type
String type = ((Element) xmlRecord.getDOM()).getAttributeNS(XMLConstants.SCHEMA_INSTANCE_URL, XMLConstants.SCHEMA_TYPE_ATTRIBUTE);
if ((null != type) && !type.equals(EMPTY_STRING)) {
XPathFragment typeFragment = new XPathFragment(type);
String namespaceURI = xmlRecord.resolveNamespacePrefix(typeFragment.getPrefix());
typeFragment.setNamespaceURI(namespaceURI);
returnDescriptor = xmlRecord.getUnmarshaller().getXMLContext().getDescriptorByGlobalType(typeFragment);
} else {
//try leaf element type
QName leafType = ((XMLField) getField()).getLastXPathFragment().getLeafElementType();
if (leafType != null) {
XPathFragment frag = new XPathFragment();
String xpath = leafType.getLocalPart();
String uri = leafType.getNamespaceURI();
if ((uri != null) && !uri.equals(EMPTY_STRING)) {
frag.setNamespaceURI(uri);
String prefix = ((XMLDescriptor) getDescriptor()).getNonNullNamespaceResolver().resolveNamespaceURI(uri);
if ((prefix != null) && !prefix.equals(EMPTY_STRING)) {
xpath = prefix + ":" + xpath;
}
}
frag.setXPath(xpath);
returnDescriptor = xmlRecord.getUnmarshaller().getXMLContext().getDescriptorByGlobalType(frag);
}
}
}