Пример #1
0
        internal static Exception CreateValidationException(XmlSchemaException exception, string message)
        {
            XmlSchemaObject?source = exception.SourceSchemaObject;

            if (exception.LineNumber == 0 && exception.LinePosition == 0)
            {
                throw new InvalidOperationException(GetSchemaItem(source, null, message), exception);
            }
            else
            {
                string?ns = null;
                if (source != null)
                {
                    while (source.Parent != null)
                    {
                        source = source.Parent;
                    }
                    if (source is XmlSchema)
                    {
                        ns = ((XmlSchema)source).TargetNamespace;
                    }
                }
                throw new InvalidOperationException(SR.Format(SR.XmlSchemaSyntaxErrorDetails, ns, message, exception.LineNumber, exception.LinePosition), exception);
            }
        }
Пример #2
0
 internal void SetSource(XmlSchemaObject source)
 {
     _sourceSchemaObject = source;
     _sourceUri          = source.SourceUri;
     _lineNumber         = source.LineNumber;
     _linePosition       = source.LinePosition;
 }
 internal static string?Namespace(XmlSchemaObject?o)
 {
     while (o != null && !(o is XmlSchema))
     {
         o = o.Parent;
     }
     return(o == null ? "" : ((XmlSchema)o).TargetNamespace);
 }
        internal string WriteXmlSchemaObject(XmlSchemaObject?o)
        {
            if (o == null)
            {
                return(string.Empty);
            }
            Write3_XmlSchemaObject((XmlSchemaObject?)o);

            return(GetString());
        }
Пример #5
0
        public bool Validate(XmlNode nodeToValidate)
        {
            XmlSchemaObject?         partialValidationType = null;
            XmlSchemaValidationFlags validationFlags       = XmlSchemaValidationFlags.AllowXmlAttributes;

            Debug.Assert(nodeToValidate.SchemaInfo != null);

            _startNode = nodeToValidate;
            switch (nodeToValidate.NodeType)
            {
            case XmlNodeType.Document:
                validationFlags |= XmlSchemaValidationFlags.ProcessIdentityConstraints;
                break;

            case XmlNodeType.DocumentFragment:
                break;

            case XmlNodeType.Element:     //Validate children of this element
                IXmlSchemaInfo   schemaInfo    = nodeToValidate.SchemaInfo;
                XmlSchemaElement?schemaElement = schemaInfo.SchemaElement;
                if (schemaElement != null)
                {
                    if (!schemaElement.RefName.IsEmpty)
                    {                                                                                 //If it is element ref,
                        partialValidationType = _schemas.GlobalElements[schemaElement.QualifiedName]; //Get Global element with correct Nillable, Default etc
                    }
                    else
                    {     //local element
                        partialValidationType = schemaElement;
                    }
                    //Verify that if there was xsi:type, the schemaElement returned has the correct type set
                    Debug.Assert(schemaElement.ElementSchemaType == schemaInfo.SchemaType);
                }
                else
                {     //Can be an element that matched xs:any and had xsi:type
                    partialValidationType = schemaInfo.SchemaType;

                    if (partialValidationType == null)
                    {     //Validated against xs:any with pc= lax or skip or undeclared / not validated element
                        if (nodeToValidate.ParentNode !.NodeType == XmlNodeType.Document)
                        {
                            //If this is the documentElement and it has not been validated at all
                            nodeToValidate = nodeToValidate.ParentNode;
                        }
                        else
                        {
                            partialValidationType = FindSchemaInfo((nodeToValidate as XmlElement) !);
                            if (partialValidationType == null)
                            {
                                throw new XmlSchemaValidationException(SR.XmlDocument_NoNodeSchemaInfo, null, nodeToValidate);
                            }
                        }
                    }
                }
                break;
Пример #6
0
 internal XmlSchemaException(string?res, string?[]?args, Exception?innerException, string?sourceUri, int lineNumber, int linePosition, XmlSchemaObject?source) :
     base(CreateMessage(res, args), innerException)
 {
     HResult             = HResults.XmlSchema;
     _res                = res;
     _args               = args;
     _sourceUri          = sourceUri;
     _lineNumber         = lineNumber;
     _linePosition       = linePosition;
     _sourceSchemaObject = source;
 }
Пример #7
0
 public bool MoveNext()
 {
     if (currentIndex >= size - 1)
     {
         currentValue = null;
         currentKey   = null;
         return(false);
     }
     currentIndex++;
     currentValue = _entries[currentIndex].xso;
     currentKey   = _entries[currentIndex].qname;
     return(true);
 }
Пример #8
0
 public override string?LookupNamespace(string prefix)
 {
     if (prefix == "xml")
     { //Special case for the XML namespace
         return(XmlReservedNs.NsXml);
     }
     for (XmlSchemaObject?current = _node; current != null; current = current.Parent)
     {
         if (current.Namespaces.TryLookupNamespace(prefix, out string?uri))
         {
             return(uri);
         }
     }
     return(prefix.Length == 0 ? string.Empty : null);
 }
Пример #9
0
        public override string?LookupPrefix(string ns)
        {
            if (ns == XmlReservedNs.NsXml)
            { //Special case for the XML namespace
                return("xml");
            }

            for (XmlSchemaObject?current = _node; current != null; current = current.Parent)
            {
                if (current.Namespaces.TryLookupPrefix(ns, out string?prefix))
                {
                    return(prefix);
                }
            }
            return(null);
        }
Пример #10
0
        internal void Insert(XmlQualifiedName name, XmlSchemaObject value)
        {
            XmlSchemaObject?oldValue = null;

            if (_table.TryGetValue(name, out oldValue))
            {
                _table[name] = value; //set new value
                Debug.Assert(oldValue != null);
                int matchedIndex = FindIndexByValue(oldValue);
                Debug.Assert(matchedIndex >= 0);
                //set new entry
                Debug.Assert(_entries[matchedIndex].qname == name);
                _entries[matchedIndex] = new XmlSchemaObjectEntry(name, value);
            }
            else
            {
                Add(name, value);
            }
        }
Пример #11
0
        internal XmlSchemaObject?AddItem(XmlSchemaObject?item, XmlQualifiedName?qname, XmlSchemas schemas)
        {
            if (item == null)
            {
                return(null);
            }
            if (qname == null || qname.IsEmpty)
            {
                return(null);
            }

            string    key  = $"{item.GetType().Name}:{qname}";
            ArrayList?list = (ArrayList?)ObjectCache[key];

            if (list == null)
            {
                list             = new ArrayList();
                ObjectCache[key] = list;
            }

            for (int i = 0; i < list.Count; i++)
            {
                XmlSchemaObject cachedItem = (XmlSchemaObject)list[i] !;
                if (cachedItem == item)
                {
                    return(cachedItem);
                }

                if (Match(cachedItem, item, true))
                {
                    return(cachedItem);
                }
                else
                {
                    Warnings.Add(SR.Format(SR.XmlMismatchSchemaObjects, item.GetType().Name, qname.Name, qname.Namespace));
                    Warnings.Add($"DEBUG:Cached item key:\r\n{(string?)looks[cachedItem]}\r\nnew item key:\r\n{(string?)looks[item]}");
                }
            }
            // no match found we need to insert the new type in the cache
            list.Add(item);
            return(item);
        }
        public override string?LookupNamespace(string prefix)
        {
            if (prefix == "xml")
            { //Special case for the XML namespace
                return(XmlReservedNs.NsXml);
            }
            Dictionary <string, string> namespaces;

            for (XmlSchemaObject?current = _node; current != null; current = current.Parent)
            {
                namespaces = current.Namespaces.Namespaces;
                if (namespaces != null && namespaces.Count > 0)
                {
                    string?uri;
                    if (namespaces.TryGetValue(prefix, out uri))
                    {
                        return(uri);
                    }
                }
            }
            return(prefix.Length == 0 ? string.Empty : null);
        }
        public override string?LookupPrefix(string ns)
        {
            if (ns == XmlReservedNs.NsXml)
            { //Special case for the XML namespace
                return("xml");
            }
            Dictionary <string, string> namespaces;

            for (XmlSchemaObject?current = _node; current != null; current = current.Parent)
            {
                namespaces = current.Namespaces.Namespaces;
                if (namespaces != null && namespaces.Count > 0)
                {
                    foreach (KeyValuePair <string, string> entry in namespaces)
                    {
                        if (entry.Value.Equals(ns))
                        {
                            return(entry.Key);
                        }
                    }
                }
            }
            return(null);
        }
Пример #14
0
 public XmlSchemaObjectCollection(XmlSchemaObject?parent)
 {
     _parent = parent;
 }
Пример #15
0
        public void Validate(XObject source, XmlSchemaObject?partialValidationType, bool addSchemaInfo)
        {
            this.source        = source;
            this.addSchemaInfo = addSchemaInfo;
            XmlSchemaValidationFlags validationFlags = XmlSchemaValidationFlags.AllowXmlAttributes;
            XmlNodeType nt = source.NodeType;

            switch (nt)
            {
            case XmlNodeType.Document:
                source = ((XDocument)source).Root !;
                if (source == null)
                {
                    throw new InvalidOperationException(SR.InvalidOperation_MissingRoot);
                }
                validationFlags |= XmlSchemaValidationFlags.ProcessIdentityConstraints;
                break;

            case XmlNodeType.Element:
                break;

            case XmlNodeType.Attribute:
                if (((XAttribute)source).IsNamespaceDeclaration)
                {
                    goto default;
                }
                if (source.Parent == null)
                {
                    throw new InvalidOperationException(SR.InvalidOperation_MissingParent);
                }
                break;

            default:
                throw new InvalidOperationException(SR.Format(SR.InvalidOperation_BadNodeType, nt));
            }
            namespaceManager = new XmlNamespaceManager(schemas.NameTable);
            PushAncestorsAndSelf(source.Parent);
            validator = new XmlSchemaValidator(schemas.NameTable, schemas, namespaceManager, validationFlags);
            validator.ValidationEventHandler += new ValidationEventHandler(ValidationCallback);
            validator.XmlResolver             = null;
            if (partialValidationType != null)
            {
                validator.Initialize(partialValidationType);
            }
            else
            {
                validator.Initialize();
            }

            IXmlLineInfo orginal = SaveLineInfo(source);

            if (nt == XmlNodeType.Attribute)
            {
                ValidateAttribute((XAttribute)source);
            }
            else
            {
                ValidateElement((XElement)source);
            }
            validator.EndValidation();
            RestoreLineInfo(orginal);
        }
Пример #16
0
        private void WriteFacets(XmlSchemaObjectCollection?facets)
        {
            if (facets == null)
            {
                return;
            }

            ArrayList a = new ArrayList();

            for (int i = 0; i < facets.Count; i++)
            {
                a.Add(facets[i]);
            }
            a.Sort(new XmlFacetComparer());
            for (int ia = 0; ia < a.Count; ia++)
            {
                XmlSchemaObject?ai = (XmlSchemaObject?)a[ia];
                if (ai is XmlSchemaMinExclusiveFacet)
                {
                    Write_XmlSchemaFacet("minExclusive", (XmlSchemaFacet)ai);
                }
                else if (ai is XmlSchemaMaxInclusiveFacet)
                {
                    Write_XmlSchemaFacet("maxInclusive", (XmlSchemaFacet)ai);
                }
                else if (ai is XmlSchemaMaxExclusiveFacet)
                {
                    Write_XmlSchemaFacet("maxExclusive", (XmlSchemaFacet)ai);
                }
                else if (ai is XmlSchemaMinInclusiveFacet)
                {
                    Write_XmlSchemaFacet("minInclusive", (XmlSchemaFacet)ai);
                }
                else if (ai is XmlSchemaLengthFacet)
                {
                    Write_XmlSchemaFacet("length", (XmlSchemaFacet)ai);
                }
                else if (ai is XmlSchemaEnumerationFacet)
                {
                    Write_XmlSchemaFacet("enumeration", (XmlSchemaFacet)ai);
                }
                else if (ai is XmlSchemaMinLengthFacet)
                {
                    Write_XmlSchemaFacet("minLength", (XmlSchemaFacet)ai);
                }
                else if (ai is XmlSchemaPatternFacet)
                {
                    Write_XmlSchemaFacet("pattern", (XmlSchemaFacet)ai);
                }
                else if (ai is XmlSchemaTotalDigitsFacet)
                {
                    Write_XmlSchemaFacet("totalDigits", (XmlSchemaFacet)ai);
                }
                else if (ai is XmlSchemaMaxLengthFacet)
                {
                    Write_XmlSchemaFacet("maxLength", (XmlSchemaFacet)ai);
                }
                else if (ai is XmlSchemaWhiteSpaceFacet)
                {
                    Write_XmlSchemaFacet("whiteSpace", (XmlSchemaFacet)ai);
                }
                else if (ai is XmlSchemaFractionDigitsFacet)
                {
                    Write_XmlSchemaFacet("fractionDigit", (XmlSchemaFacet)ai);
                }
            }
        }
Пример #17
0
 internal static XmlQualifiedName NameOf(XmlSchemaObject?o)
 {
     if (o is XmlSchemaAttribute)
     {
         return(((XmlSchemaAttribute)o).QualifiedName);
     }
     else if (o is XmlSchemaAttributeGroup)
     {
         return(((XmlSchemaAttributeGroup)o).QualifiedName);
     }
     else if (o is XmlSchemaComplexType)
     {
         return(((XmlSchemaComplexType)o).QualifiedName);
     }
     else if (o is XmlSchemaSimpleType)
     {
         return(((XmlSchemaSimpleType)o).QualifiedName);
     }
     else if (o is XmlSchemaElement)
     {
         return(((XmlSchemaElement)o).QualifiedName);
     }
     else if (o is XmlSchemaGroup)
     {
         return(((XmlSchemaGroup)o).QualifiedName);
     }
     else if (o is XmlSchemaGroupRef)
     {
         return(((XmlSchemaGroupRef)o).RefName);
     }
     else if (o is XmlSchemaNotation)
     {
         return(((XmlSchemaNotation)o).QualifiedName);
     }
     else if (o is XmlSchemaSequence)
     {
         XmlSchemaSequence s = (XmlSchemaSequence)o;
         if (s.Items.Count == 0)
         {
             return(new XmlQualifiedName(".sequence", Namespace(o)));
         }
         return(NameOf(s.Items[0]));
     }
     else if (o is XmlSchemaAll)
     {
         XmlSchemaAll a = (XmlSchemaAll)o;
         if (a.Items.Count == 0)
         {
             return(new XmlQualifiedName(".all", Namespace(o)));
         }
         return(NameOf(a.Items));
     }
     else if (o is XmlSchemaChoice)
     {
         XmlSchemaChoice c = (XmlSchemaChoice)o;
         if (c.Items.Count == 0)
         {
             return(new XmlQualifiedName(".choice", Namespace(o)));
         }
         return(NameOf(c.Items));
     }
     else if (o is XmlSchemaAny)
     {
         return(new XmlQualifiedName("*", SchemaObjectWriter.ToString(((XmlSchemaAny)o).NamespaceList)));
     }
     else if (o is XmlSchemaIdentityConstraint)
     {
         return(((XmlSchemaIdentityConstraint)o).QualifiedName);
     }
     return(new XmlQualifiedName("?", Namespace(o)));
 }
Пример #18
0
        private void Write3_XmlSchemaObject(XmlSchemaObject?o)
        {
            if ((object?)o == null)
            {
                return;
            }
            System.Type t = o.GetType();

            if (t == typeof(XmlSchemaComplexType))
            {
                Write35_XmlSchemaComplexType((XmlSchemaComplexType)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleType))
            {
                Write9_XmlSchemaSimpleType((XmlSchemaSimpleType)o);
                return;
            }
            else if (t == typeof(XmlSchemaElement))
            {
                Write46_XmlSchemaElement((XmlSchemaElement)o);
                return;
            }
            else if (t == typeof(XmlSchemaAppInfo))
            {
                Write7_XmlSchemaAppInfo((XmlSchemaAppInfo)o);
                return;
            }
            else if (t == typeof(XmlSchemaDocumentation))
            {
                Write6_XmlSchemaDocumentation((XmlSchemaDocumentation)o);
                return;
            }
            else if (t == typeof(XmlSchemaAnnotation))
            {
                Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o);
                return;
            }
            else if (t == typeof(XmlSchemaGroup))
            {
                Write57_XmlSchemaGroup((XmlSchemaGroup)o);
                return;
            }
            else if (t == typeof(XmlSchemaXPath))
            {
                Write49_XmlSchemaXPath("xpath", "", (XmlSchemaXPath)o);
                return;
            }
            else if (t == typeof(XmlSchemaIdentityConstraint))
            {
                Write48_XmlSchemaIdentityConstraint((XmlSchemaIdentityConstraint)o);
                return;
            }
            else if (t == typeof(XmlSchemaUnique))
            {
                Write51_XmlSchemaUnique((XmlSchemaUnique)o);
                return;
            }
            else if (t == typeof(XmlSchemaKeyref))
            {
                Write50_XmlSchemaKeyref((XmlSchemaKeyref)o);
                return;
            }
            else if (t == typeof(XmlSchemaKey))
            {
                Write47_XmlSchemaKey((XmlSchemaKey)o);
                return;
            }
            else if (t == typeof(XmlSchemaGroupRef))
            {
                Write55_XmlSchemaGroupRef((XmlSchemaGroupRef)o);
                return;
            }
            else if (t == typeof(XmlSchemaAny))
            {
                Write53_XmlSchemaAny((XmlSchemaAny)o);
                return;
            }
            else if (t == typeof(XmlSchemaSequence))
            {
                Write54_XmlSchemaSequence((XmlSchemaSequence)o);
                return;
            }
            else if (t == typeof(XmlSchemaChoice))
            {
                Write52_XmlSchemaChoice((XmlSchemaChoice)o);
                return;
            }
            else if (t == typeof(XmlSchemaAll))
            {
                Write43_XmlSchemaAll((XmlSchemaAll)o);
                return;
            }
            else if (t == typeof(XmlSchemaComplexContentRestriction))
            {
                Write56_XmlSchemaComplexContentRestriction((XmlSchemaComplexContentRestriction)o);
                return;
            }
            else if (t == typeof(XmlSchemaComplexContentExtension))
            {
                Write42_XmlSchemaComplexContentExtension((XmlSchemaComplexContentExtension)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleContentRestriction))
            {
                Write40_XmlSchemaSimpleContentRestriction((XmlSchemaSimpleContentRestriction)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleContentExtension))
            {
                Write38_XmlSchemaSimpleContentExtension((XmlSchemaSimpleContentExtension)o);
                return;
            }
            else if (t == typeof(XmlSchemaComplexContent))
            {
                Write41_XmlSchemaComplexContent((XmlSchemaComplexContent)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleContent))
            {
                Write36_XmlSchemaSimpleContent((XmlSchemaSimpleContent)o);
                return;
            }
            else if (t == typeof(XmlSchemaAnyAttribute))
            {
                Write33_XmlSchemaAnyAttribute((XmlSchemaAnyAttribute)o);
                return;
            }
            else if (t == typeof(XmlSchemaAttributeGroupRef))
            {
                Write32_XmlSchemaAttributeGroupRef((XmlSchemaAttributeGroupRef)o);
                return;
            }
            else if (t == typeof(XmlSchemaAttributeGroup))
            {
                Write31_XmlSchemaAttributeGroup((XmlSchemaAttributeGroup)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleTypeRestriction))
            {
                Write15_XmlSchemaSimpleTypeRestriction((XmlSchemaSimpleTypeRestriction)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleTypeList))
            {
                Write14_XmlSchemaSimpleTypeList((XmlSchemaSimpleTypeList)o);
                return;
            }
            else if (t == typeof(XmlSchemaSimpleTypeUnion))
            {
                Write12_XmlSchemaSimpleTypeUnion((XmlSchemaSimpleTypeUnion)o);
                return;
            }
            else if (t == typeof(XmlSchemaAttribute))
            {
                Write1_XmlSchemaAttribute((XmlSchemaAttribute)o);
                return;
            }
        }
Пример #19
0
        internal object?Find(XmlQualifiedName name, Type type, bool checkCache)
        {
            if (!IsCompiled)
            {
                foreach (XmlSchema schema in List)
                {
                    Preprocess(schema);
                }
            }
            IList values = (IList)SchemaSet.Schemas(name.Namespace);

            if (values == null)
            {
                return(null);
            }

            foreach (XmlSchema schema in values)
            {
                Preprocess(schema);

                XmlSchemaObject?ret = null;
                if (typeof(XmlSchemaType).IsAssignableFrom(type))
                {
                    ret = schema.SchemaTypes[name];
                    if (ret == null || !type.IsAssignableFrom(ret.GetType()))
                    {
                        continue;
                    }
                }
                else if (type == typeof(XmlSchemaGroup))
                {
                    ret = schema.Groups[name];
                }
                else if (type == typeof(XmlSchemaAttributeGroup))
                {
                    ret = schema.AttributeGroups[name];
                }
                else if (type == typeof(XmlSchemaElement))
                {
                    ret = schema.Elements[name];
                }
                else if (type == typeof(XmlSchemaAttribute))
                {
                    ret = schema.Attributes[name];
                }
                else if (type == typeof(XmlSchemaNotation))
                {
                    ret = schema.Notations[name];
                }
#if DEBUG
                else
                {
                    // use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe
                    throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorDetails, "XmlSchemas.Find: Invalid object type " + type.FullName));
                }
#endif

                if (ret != null && _shareTypes && checkCache && !IsReference(ret))
                {
                    ret = Cache.AddItem(ret, name, this);
                }
                if (ret != null)
                {
                    return(ret);
                }
            }
            return(null);
        }
Пример #20
0
        private void Merge(IList originals, XmlSchema schema)
        {
            foreach (XmlSchema s in originals)
            {
                if (schema == s)
                {
                    return;
                }
            }

            foreach (XmlSchemaExternal external in schema.Includes)
            {
                if (external is XmlSchemaImport)
                {
                    external.SchemaLocation = null;
                    if (external.Schema != null)
                    {
                        Merge(external.Schema);
                    }
                    else
                    {
                        AddImport(originals, ((XmlSchemaImport)external).Namespace);
                    }
                }
                else
                {
                    if (external.Schema == null)
                    {
                        // we do not process includes or redefines by the schemaLocation
                        if (external.SchemaLocation != null)
                        {
                            throw new InvalidOperationException(SR.Format(SR.XmlSchemaIncludeLocation, this.GetType().Name, external.SchemaLocation));
                        }
                    }
                    else
                    {
                        external.SchemaLocation = null;
                        Merge(originals, external.Schema);
                    }
                }
            }

            // bring all included items to the parent schema;
            bool[] matchedItems = new bool[schema.Items.Count];
            int    count        = 0;

            for (int i = 0; i < schema.Items.Count; i++)
            {
                XmlSchemaObject o    = schema.Items[i];
                XmlSchemaObject?dest = Find(o, originals);
                if (dest != null)
                {
                    if (!Cache.Match(dest, o, _shareTypes))
                    {
                        throw new InvalidOperationException(MergeFailedMessage(o, dest, schema.TargetNamespace));
                    }
                    matchedItems[i] = true;
                    count++;
                }
            }
            if (count != schema.Items.Count)
            {
                XmlSchema destination = (XmlSchema)originals[0] !;
                for (int i = 0; i < schema.Items.Count; i++)
                {
                    if (!matchedItems[i])
                    {
                        destination.Items.Add(schema.Items[i]);
                    }
                }
                destination.IsPreprocessed = false;
                Preprocess(destination);
            }
        }
Пример #21
0
 public void Reset()
 {
     currentIndex = -1;
     currentValue = null;
     currentKey   = null;
 }
Пример #22
0
        private static string?GetSchemaItem(XmlSchemaObject?o, string?ns, string?details)
        {
            if (o == null)
            {
                return(null);
            }
            while (o.Parent != null && !(o.Parent is XmlSchema))
            {
                o = o.Parent;
            }
            if (ns == null || ns.Length == 0)
            {
                XmlSchemaObject tmp = o;
                while (tmp.Parent != null)
                {
                    tmp = tmp.Parent;
                }
                if (tmp is XmlSchema)
                {
                    ns = ((XmlSchema)tmp).TargetNamespace;
                }
            }
            string?item = null;

            if (o is XmlSchemaNotation)
            {
                item = SR.Format(SR.XmlSchemaNamedItem, ns, "notation", ((XmlSchemaNotation)o).Name, details);
            }
            else if (o is XmlSchemaGroup)
            {
                item = SR.Format(SR.XmlSchemaNamedItem, ns, "group", ((XmlSchemaGroup)o).Name, details);
            }
            else if (o is XmlSchemaElement)
            {
                XmlSchemaElement e = ((XmlSchemaElement)o);
                if (e.Name == null || e.Name.Length == 0)
                {
                    XmlQualifiedName parentName = XmlSchemas.GetParentName(o);
                    // Element reference '{0}' declared in schema type '{1}' from namespace '{2}'
                    item = SR.Format(SR.XmlSchemaElementReference, e.RefName.ToString(), parentName.Name, parentName.Namespace);
                }
                else
                {
                    item = SR.Format(SR.XmlSchemaNamedItem, ns, "element", e.Name, details);
                }
            }
            else if (o is XmlSchemaType)
            {
                item = SR.Format(SR.XmlSchemaNamedItem, ns, o.GetType() == typeof(XmlSchemaSimpleType) ? "simpleType" : "complexType", ((XmlSchemaType)o).Name, null);
            }
            else if (o is XmlSchemaAttributeGroup)
            {
                item = SR.Format(SR.XmlSchemaNamedItem, ns, "attributeGroup", ((XmlSchemaAttributeGroup)o).Name, details);
            }
            else if (o is XmlSchemaAttribute)
            {
                XmlSchemaAttribute a = ((XmlSchemaAttribute)o);
                if (a.Name == null || a.Name.Length == 0)
                {
                    XmlQualifiedName parentName = XmlSchemas.GetParentName(o);
                    // Attribure reference '{0}' declared in schema type '{1}' from namespace '{2}'
                    return(SR.Format(SR.XmlSchemaAttributeReference, a.RefName.ToString(), parentName.Name, parentName.Namespace));
                }
                else
                {
                    item = SR.Format(SR.XmlSchemaNamedItem, ns, "attribute", a.Name, details);
                }
            }
            else if (o is XmlSchemaContent)
            {
                XmlQualifiedName parentName = XmlSchemas.GetParentName(o);
                // Check content definition of schema type '{0}' from namespace '{1}'. {2}
                item = SR.Format(SR.XmlSchemaContentDef, parentName.Name, parentName.Namespace, null);
            }
            else if (o is XmlSchemaExternal)
            {
                string itemType = o is XmlSchemaImport ? "import" : o is XmlSchemaInclude ? "include" : o is XmlSchemaRedefine ? "redefine" : o.GetType().Name;
                item = SR.Format(SR.XmlSchemaItem, ns, itemType, details);
            }
            else if (o is XmlSchema)
            {
                item = SR.Format(SR.XmlSchema, ns, details);
            }
            else
            {
                item = SR.Format(SR.XmlSchemaNamedItem, ns, o.GetType().Name, null, details);
            }

            return(item);
        }
Пример #23
0
 internal void SetSchemaObject(XmlSchemaObject source)
 {
     _sourceSchemaObject = source;
 }
Пример #24
0
        internal SchemaAttDef?GetAttributeXsd(SchemaElementDecl?ed, XmlQualifiedName qname, XmlSchemaObject?partialValidationType, out AttributeMatchState attributeMatchState)
        {
            SchemaAttDef?attdef = null;

            attributeMatchState = AttributeMatchState.UndeclaredAttribute;
            if (ed != null)
            {
                attdef = ed.GetAttDef(qname);
                if (attdef != null)
                {
                    attributeMatchState = AttributeMatchState.AttributeFound;
                    return(attdef);
                }
                XmlSchemaAnyAttribute?any = ed.AnyAttribute;
                if (any != null)
                {
                    if (!any.NamespaceList !.Allows(qname))
                    {
                        attributeMatchState = AttributeMatchState.ProhibitedAnyAttribute;
                    }
                    else if (any.ProcessContentsCorrect != XmlSchemaContentProcessing.Skip)
                    {
                        if (_attributeDecls.TryGetValue(qname, out attdef))
                        {
                            if (attdef.Datatype.TypeCode == XmlTypeCode.Id)
                            { //anyAttribute match whose type is ID
                                attributeMatchState = AttributeMatchState.AnyIdAttributeFound;
                            }
                            else
                            {
                                attributeMatchState = AttributeMatchState.AttributeFound;
                            }
                        }
                        else if (any.ProcessContentsCorrect == XmlSchemaContentProcessing.Lax)
                        {
                            attributeMatchState = AttributeMatchState.AnyAttributeLax;
                        }
                    }
                    else
                    {
                        attributeMatchState = AttributeMatchState.AnyAttributeSkip;
                    }
                }
                else if (ed.ProhibitedAttributes.ContainsKey(qname))
                {
                    attributeMatchState = AttributeMatchState.ProhibitedAttribute;
                }
            }
Пример #25
0
        protected void AddToTable(XmlSchemaObjectTable table, XmlQualifiedName qname, XmlSchemaObject item)
        {
            if (qname.Name.Length == 0)
            {
                return;
            }
            XmlSchemaObject?existingObject = (XmlSchemaObject?)table[qname];

            if (existingObject != null)
            {
                if (existingObject == item)
                {
                    return;
                }
                string code = SR.Sch_DupGlobalElement;
                if (item is XmlSchemaAttributeGroup)
                {
                    string ns = _nameTable.Add(qname.Namespace);
                    if (Ref.Equal(ns, _nsXml))
                    { //Check for xml namespace
                        XmlSchema       schemaForXmlNS        = Preprocessor.GetBuildInSchema();
                        XmlSchemaObject?builtInAttributeGroup = schemaForXmlNS.AttributeGroups[qname];
                        if ((object)existingObject == (object?)builtInAttributeGroup)
                        {
                            table.Insert(qname, item);
                            return;
                        }
                        else if ((object)item == (object?)builtInAttributeGroup)
                        { //trying to overwrite customer's component with built-in, ignore built-in
                            return;
                        }
                    }
                    else if (IsValidAttributeGroupRedefine(existingObject, item, table))
                    { //check for redefines
                        return;
                    }
                    code = SR.Sch_DupAttributeGroup;
                }
                else if (item is XmlSchemaAttribute)
                {
                    string ns = _nameTable.Add(qname.Namespace);
                    if (Ref.Equal(ns, _nsXml))
                    {
                        XmlSchema       schemaForXmlNS   = Preprocessor.GetBuildInSchema();
                        XmlSchemaObject?builtInAttribute = schemaForXmlNS.Attributes[qname];
                        if ((object)existingObject == (object?)builtInAttribute)
                        { //replace built-in one
                            table.Insert(qname, item);
                            return;
                        }
                        else if ((object)item == (object?)builtInAttribute)
                        { //trying to overwrite customer's component with built-in, ignore built-in
                            return;
                        }
                    }
                    code = SR.Sch_DupGlobalAttribute;
                }
                else if (item is XmlSchemaSimpleType)
                {
                    if (IsValidTypeRedefine(existingObject, item, table))
                    {
                        return;
                    }
                    code = SR.Sch_DupSimpleType;
                }
                else if (item is XmlSchemaComplexType)
                {
                    if (IsValidTypeRedefine(existingObject, item, table))
                    {
                        return;
                    }
                    code = SR.Sch_DupComplexType;
                }
                else if (item is XmlSchemaGroup)
                {
                    if (IsValidGroupRedefine(existingObject, item, table))
                    { //check for redefines
                        return;
                    }
                    code = SR.Sch_DupGroup;
                }
                else if (item is XmlSchemaNotation)
                {
                    code = SR.Sch_DupNotation;
                }
                else if (item is XmlSchemaIdentityConstraint)
                {
                    code = SR.Sch_DupIdentityConstraint;
                }
                else
                {
                    Debug.Assert(item is XmlSchemaElement);
                }
                SendValidationEvent(code, qname.ToString(), item);
            }
            else
            {
                table.Add(qname, item);
            }
        }