diff --git a/xml.schema.completion/src/org/netbeans/modules/xml/schema/completion/util/CompletionUtil.java b/xml.schema.completion/src/org/netbeans/modules/xml/schema/completion/util/CompletionUtil.java --- a/xml.schema.completion/src/org/netbeans/modules/xml/schema/completion/util/CompletionUtil.java +++ b/xml.schema.completion/src/org/netbeans/modules/xml/schema/completion/util/CompletionUtil.java @@ -609,7 +609,7 @@ AXIComponent child = null; for(QName qname : path) { - child = findChildElement(parent, qname); + child = findChildElement(parent, qname,context); parent = child; } @@ -620,7 +620,7 @@ } private static AXIComponent findChildElement(AXIComponent parent, - QName qname) { + QName qname, CompletionContextImpl context) { if(parent == null) return null; for(AXIComponent element : parent.getChildElements()) { @@ -630,7 +630,31 @@ Element e = (Element)element; if(qname.getLocalPart().equals(e.getName())) return element; + + if(e.isReference()){ + Element ref=e.getReferent(); + if(qname.getLocalPart().equals(ref.getName())){ + return ref; + } + // check substitutions + AXIModel model = ref.getModel(); + String nsUri = ref.getTargetNamespace(); + String localName = ref.getName(); + for (CompletionModel completionModel : context.getCompletionModels()) { + SchemaModel schemaModel = completionModel.getSchemaModel(); + Set substitutions = FindSubstitutions.resolveSubstitutions(schemaModel, nsUri, localName); + for (GlobalElement substitution : substitutions) { + AXIComponent substitutionElement = getAxiComponent(model, substitution); + if(substitutionElement instanceof Element){ + if(qname.getLocalPart().equals(((Element)substitutionElement).getName())){ + return substitutionElement; + } + } + } + } + } } + for (AXIComponent c : parent.getChildren()) { if (c instanceof SchemaReference) { SchemaReference ref = (SchemaReference)c; @@ -639,7 +663,7 @@ try { model = in.resolveReferencedModel(); AXIModel am = AXIModelFactory.getDefault().getModel(model); - AXIComponent check = findChildElement(am.getRoot(), qname); + AXIComponent check = findChildElement(am.getRoot(), qname,context); if (check != null) { return check; }