Ejemplo n.º 1
0
        internal void CheckDuplicateElement(XmlSchemaElement element, string elementNs)
        {
            if (element == null)
            {
                return;
            }

            // only check duplicate definitions for top-level element
            if (element.Parent == null || !(element.Parent is XmlSchema))
            {
                return;
            }

            XmlSchemaObjectTable elements = null;

            if (Schema != null && Schema.TargetNamespace == elementNs)
            {
#if !XMLSERIALIZERGENERATOR
                XmlSchemas.Preprocess(Schema);
                elements = Schema.Elements;
#endif
            }
            else if (Schemas != null)
            {
                elements = Schemas.GlobalElements;
            }
            else
            {
                return;
            }
            foreach (XmlSchemaElement e in elements.Values)
            {
                if (e.Name == element.Name && e.QualifiedName.Namespace == elementNs)
                {
                    if (Match(e, element))
                    {
                        return;
                    }
                    // XmlSerializableRootDupName=Cannot reconcile schema for '{0}'. Please use [XmlRoot] attribute to change name or namepace of the top-level element to avoid duplicate element declarations: element name='{1} namespace='{2}'.
                    throw new InvalidOperationException(SR.Format(SR.XmlSerializableRootDupName, _getSchemaMethod.DeclaringType.FullName, e.Name, elementNs));
                }
            }
        }