String[] doctypeInfo = getDoctypeInfo(document);
if (doctypeInfo != null)
{
// we have detected doctype information so we assume that we can locate the CMElementDeclaration
// in the CMDocument's table of global elements
CMDocument cmDocument = getCorrespondingCMDocument(element, false);
// TODO... consider replacing above with
// CMDocument cmDocument = getCMDocument(document, doctypeInfo[0], doctypeInfo[1]);
if (cmDocument != null)
{
result = (CMElementDeclaration)cmDocument.getElements().getNamedItem(element.getNodeName());
// this is a hack to get our xsl code assist working... we might want to handle similar
// grammar behaviour via some established model query setting
if (result == null && getImplictDoctype(document) != null)
{
Node parent = element.getParentNode();
if (parent != null && parent.getNodeType() == Node.ELEMENT_NODE)
{
result = getCMElementDeclaration((Element)parent);
}
}
}
}
else
{
// here we use a namespaceTable to consider if the root element has any namespace information
//
NamespaceTable namespaceTable = new NamespaceTable(element.getOwnerDocument());
List list = NamespaceTable.getElementLineage(element);
Element rootElement = (Element)list.get(0);
namespaceTable.addElement(rootElement);
if (namespaceTable.isNamespaceEncountered())
{
// we assume that this is an XMLSchema style namespace aware document
result = getCMElementDeclaration(element, list, namespaceTable);
}
else
{
result = checkExternalSchema(element);
if (result == null) {
// we assume that this is an inferred CMDocument for a DTD style 'namespaceless' document
CMDocument cmDocument = getCMDocument("", "", "DTD"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
if (cmDocument != null) {
result = (CMElementDeclaration)cmDocument.getElements().getNamedItem(element.getNodeName());
}
}
}
}
return result;