Inheritance: System.Collections.CollectionBase
Beispiel #1
0
		public XmlSchemaRedefine()
		{
			attributeGroups = new XmlSchemaObjectTable();
			groups = new XmlSchemaObjectTable();
			items = new XmlSchemaObjectCollection(this);
			schemaTypes = new XmlSchemaObjectTable();
		}
        void Write5_XmlSchemaAnnotation(XmlSchemaAnnotation o)
        {
            if ((object)o == null)
            {
                return;
            }
            WriteStartElement("annotation");

            WriteAttribute(@"id", @"", ((System.String)o.@Id));
            WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o);
            System.Xml.Schema.XmlSchemaObjectCollection a = (System.Xml.Schema.XmlSchemaObjectCollection)o.@Items;
            if (a != null)
            {
                for (int ia = 0; ia < a.Count; ia++)
                {
                    XmlSchemaObject ai = (XmlSchemaObject)a[ia];
                    if (ai is XmlSchemaAppInfo)
                    {
                        Write7_XmlSchemaAppInfo((XmlSchemaAppInfo)ai);
                    }
                    else if (ai is XmlSchemaDocumentation)
                    {
                        Write6_XmlSchemaDocumentation((XmlSchemaDocumentation)ai);
                    }
                }
            }
            WriteEndElement();
        }
Beispiel #3
0
 void AddAttributes(ClassInfo classInfo, XmlSchemaObjectCollection attributes)
 {
     foreach (XmlSchemaAttribute attribute in attributes)
     {
         classInfo.Attributes.Add(PropertyFromAttribute(classInfo, attribute));
     }
 }
        public static void WriteConstraintsSection(this MamlWriter writer, Context context, XmlSchemaObjectCollection constraints)
        {
            if (!context.Configuration.DocumentConstraints)
                return;

            writer.StartSection("Constraints", "constraints");
            writer.WriteConstraintTable(context, constraints);
            writer.EndSection();
        }
Beispiel #5
0
		public XmlSchemaElement()
		{
			block = XmlSchemaDerivationMethod.None;
			final = XmlSchemaDerivationMethod.None;
			constraints = new XmlSchemaObjectCollection();
			refName = XmlQualifiedName.Empty;
			schemaTypeName = XmlQualifiedName.Empty;
			substitutionGroup = XmlQualifiedName.Empty;
			InitPostCompileInformations ();
		}
 void ReadDocumentationFromAnnotation(XmlSchemaObjectCollection annotationItems)
 {
     foreach (XmlSchemaObject schemaObject in annotationItems) {
         XmlSchemaDocumentation schemaDocumentation = schemaObject as XmlSchemaDocumentation;
         if (schemaDocumentation != null) {
             ReadSchemaDocumentationFromMarkup(schemaDocumentation.Markup);
         }
     }
     RemoveWhitespaceFromDocumentation();
 }
Beispiel #7
0
 private static void EnumerateDocumentedItems(XmlSchemaObjectCollection schemaItems, Dictionary<string, string> documentedItems)
 {
     foreach (XmlSchemaObject schemaObj in schemaItems)
     {
         string documentation = GetDocumenation(schemaObj);
         if (documentation != null)
         {
             string uniqueName = GetUniqueName(schemaObj);
             documentedItems[uniqueName] = documentation;
         }
         EnumerateDocumentedItems(schemaObj, documentedItems);
     }
 }
		public XmlSchema ()
		{
			attributeFormDefault= XmlSchemaForm.None;
			blockDefault = XmlSchemaDerivationMethod.None;
			elementFormDefault = XmlSchemaForm.None;
			finalDefault = XmlSchemaDerivationMethod.None;
			includes = new XmlSchemaObjectCollection();
			isCompiled = false;
			items = new XmlSchemaObjectCollection();
			attributeGroups = new XmlSchemaObjectTable();
			attributes = new XmlSchemaObjectTable();
			elements = new XmlSchemaObjectTable();
			groups = new XmlSchemaObjectTable();
			notations = new XmlSchemaObjectTable();
			schemaTypes = new XmlSchemaObjectTable();
		}
Beispiel #9
0
        // It makes complexType not to have Simple content model.
        private void ToComplexContentType(ComplexType type)
        {
            SimpleModel sm = type.ContentModel as SimpleModel;

            if (sm == null)
            {
                return;
            }

            SOMList atts = GetAttributes(type);

            foreach (SOMObject o in atts)
            {
                type.Attributes.Add(o);
            }
            // FIXME: need to copy AnyAttribute.
            // (though not considered right now)
            type.ContentModel = null;
            type.IsMixed      = true;
        }
Beispiel #10
0
 private static string Process(XmlSchemaObjectCollection collection)
 {
     StringBuilder result = new StringBuilder();
     foreach (XmlSchemaObject schemaObject in collection)
     {
         if (schemaObject is XmlSchemaDocumentation)
             result.Append(ProcessDocumentation((XmlSchemaDocumentation)schemaObject));
         else if (schemaObject is XmlSchemaElement)
             result.Append(ProcessElement((XmlSchemaElement)schemaObject));
         else if (schemaObject is XmlSchemaAnnotation)
             result.Append(ProcessAnnotation((XmlSchemaAnnotation)schemaObject));
         else if (schemaObject is XmlSchemaAttribute)
             result.Append(ProcessAttribute((XmlSchemaAttribute)schemaObject));
         else if (schemaObject is XmlSchemaSimpleType)
             result.Append(ProcessSchemaSimpleType((XmlSchemaSimpleType)schemaObject));
         else
             result.AppendLine(string.Format("Unsupported type: {0}", schemaObject));
     }
     return result.ToString();
 }
        private static void WriteConstraintFieldList(this MamlWriter writer, XmlSchemaObjectCollection fields)
        {
            if (fields.Count == 1)
            {
                var field = (XmlSchemaXPath)fields[0];
                writer.WriteString(field.XPath);
                return;
            }

            writer.StartList(ListClass.Ordered);

            foreach (XmlSchemaXPath field in fields)
            {
                writer.StartListItem();
                writer.StartParagraph();
                writer.WriteString(field.XPath);
                writer.EndParagraph();
                writer.EndListItem();
            }

            writer.EndList();
        }
        public static void WriteConstraintTable(this MamlWriter writer, Context context, XmlSchemaObjectCollection constraints)
        {
            if (constraints.Count == 0)
                return;

            writer.StartTable();
            writer.StartTableHeader();
            writer.StartTableRow();

            writer.StartTableRowEntry();
            writer.EndTableRowEntry();

            writer.StartTableRowEntry();
            writer.WriteString("Type");
            writer.EndTableRowEntry();

            writer.StartTableRowEntry();
            writer.WriteString("Description");
            writer.EndTableRowEntry();

            writer.StartTableRowEntry();
            writer.WriteString("Selector");
            writer.EndTableRowEntry();

            writer.StartTableRowEntry();
            writer.WriteString("Fields");
            writer.EndTableRowEntry();

            writer.EndTableRow();
            writer.EndTableHeader();

            var rowBuilder = new ConstraintRowWriter(writer, context);
            rowBuilder.Traverse(constraints);

            writer.EndTable();
        }
Beispiel #13
0
        private Hashtable CollectAttrTable(SOMList attList)
        {
            // get attribute definition table.
            Hashtable table = new Hashtable();

            foreach (XmlSchemaObject obj in attList)
            {
                Attr attr = obj as Attr;
                if (attr == null)
                {
                    throw Error(obj, String.Format("Attribute inference only supports direct attribute definition. {0} is not supported.", obj.GetType()));
                }
                if (attr.RefName != QName.Empty)
                {
                    table.Add(attr.RefName, attr);
                }
                else
                {
                    table.Add(new QName(attr.Name, ""),
                              attr);
                }
            }
            return(table);
        }
 private void Add(XmlSchemaObjectCollection collToAdd) {
     this.InnerList.InsertRange(0, collToAdd);
 }
 internal void SetAttributes(XmlSchemaObjectCollection newAttributes) {
     attributes = newAttributes;
 }
Beispiel #16
0
 public XmlSchemaComplexContentRestriction()
 {
     baseTypeName = XmlQualifiedName.Empty;
     attributes   = new XmlSchemaObjectCollection();
 }
Beispiel #17
0
        public static int ValidateAttributesResolved(XmlSchemaObjectTable attributesResolved, ValidationEventHandler h, XmlSchema schema, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, ref XmlSchemaAnyAttribute anyAttributeUse, XmlSchemaAttributeGroup redefined, bool skipEquivalent)
        {
            int num = 0;

            if (anyAttribute != null && anyAttributeUse == null)
            {
                anyAttributeUse = anyAttribute;
            }
            ArrayList arrayList = new ArrayList();

            foreach (XmlSchemaObject xmlSchemaObject in attributes)
            {
                XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = xmlSchemaObject as XmlSchemaAttributeGroupRef;
                if (xmlSchemaAttributeGroupRef != null)
                {
                    XmlSchemaAttributeGroup xmlSchemaAttributeGroup = null;
                    if (redefined != null && xmlSchemaAttributeGroupRef.RefName == redefined.QualifiedName)
                    {
                        xmlSchemaAttributeGroup = redefined;
                    }
                    else
                    {
                        xmlSchemaAttributeGroup = schema.FindAttributeGroup(xmlSchemaAttributeGroupRef.RefName);
                    }
                    if (xmlSchemaAttributeGroup == null)
                    {
                        if (!schema.missedSubComponents)
                        {
                            xmlSchemaAttributeGroupRef.error(h, "Referenced attribute group " + xmlSchemaAttributeGroupRef.RefName + " was not found in the corresponding schema.");
                        }
                    }
                    else if (xmlSchemaAttributeGroup.AttributeGroupRecursionCheck)
                    {
                        xmlSchemaAttributeGroup.error(h, "Attribute group recursion was found: " + xmlSchemaAttributeGroupRef.RefName);
                    }
                    else
                    {
                        try
                        {
                            xmlSchemaAttributeGroup.AttributeGroupRecursionCheck = true;
                            num += xmlSchemaAttributeGroup.Validate(h, schema);
                        }
                        finally
                        {
                            xmlSchemaAttributeGroup.AttributeGroupRecursionCheck = false;
                        }
                        if (xmlSchemaAttributeGroup.AnyAttributeUse != null && anyAttribute == null)
                        {
                            anyAttributeUse = xmlSchemaAttributeGroup.AnyAttributeUse;
                        }
                        foreach (object obj in xmlSchemaAttributeGroup.AttributeUses)
                        {
                            XmlSchemaAttribute xmlSchemaAttribute = (XmlSchemaAttribute)((DictionaryEntry)obj).Value;
                            if (!XmlSchemaUtil.StrictMsCompliant || xmlSchemaAttribute.Use != XmlSchemaUse.Prohibited)
                            {
                                if (xmlSchemaAttribute.RefName != null && xmlSchemaAttribute.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !XmlSchemaUtil.AreAttributesEqual(xmlSchemaAttribute, attributesResolved[xmlSchemaAttribute.RefName] as XmlSchemaAttribute)))
                                {
                                    XmlSchemaUtil.AddToTable(attributesResolved, xmlSchemaAttribute, xmlSchemaAttribute.RefName, h);
                                }
                                else if (!skipEquivalent || !XmlSchemaUtil.AreAttributesEqual(xmlSchemaAttribute, attributesResolved[xmlSchemaAttribute.QualifiedName] as XmlSchemaAttribute))
                                {
                                    XmlSchemaUtil.AddToTable(attributesResolved, xmlSchemaAttribute, xmlSchemaAttribute.QualifiedName, h);
                                }
                            }
                        }
                    }
                }
                else
                {
                    XmlSchemaAttribute xmlSchemaAttribute2 = xmlSchemaObject as XmlSchemaAttribute;
                    if (xmlSchemaAttribute2 != null)
                    {
                        num += xmlSchemaAttribute2.Validate(h, schema);
                        if (arrayList.Contains(xmlSchemaAttribute2.QualifiedName))
                        {
                            xmlSchemaAttribute2.error(h, string.Format("Duplicate attributes was found for '{0}'", xmlSchemaAttribute2.QualifiedName));
                        }
                        arrayList.Add(xmlSchemaAttribute2.QualifiedName);
                        if (!XmlSchemaUtil.StrictMsCompliant || xmlSchemaAttribute2.Use != XmlSchemaUse.Prohibited)
                        {
                            if (xmlSchemaAttribute2.RefName != null && xmlSchemaAttribute2.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !XmlSchemaUtil.AreAttributesEqual(xmlSchemaAttribute2, attributesResolved[xmlSchemaAttribute2.RefName] as XmlSchemaAttribute)))
                            {
                                XmlSchemaUtil.AddToTable(attributesResolved, xmlSchemaAttribute2, xmlSchemaAttribute2.RefName, h);
                            }
                            else if (!skipEquivalent || !XmlSchemaUtil.AreAttributesEqual(xmlSchemaAttribute2, attributesResolved[xmlSchemaAttribute2.QualifiedName] as XmlSchemaAttribute))
                            {
                                XmlSchemaUtil.AddToTable(attributesResolved, xmlSchemaAttribute2, xmlSchemaAttribute2.QualifiedName, h);
                            }
                        }
                    }
                    else if (anyAttribute == null)
                    {
                        anyAttributeUse = (XmlSchemaAnyAttribute)xmlSchemaObject;
                        anyAttribute.Validate(h, schema);
                    }
                }
            }
            return(num);
        }
Beispiel #18
0
            private XmlSchemaAttribute AddAttribute(string localName, string prefix, string childURI, string attrValue, bool bCreatingNewType, XmlSchema parentSchema, XmlSchemaObjectCollection addLocation, XmlSchemaObjectTable compiledAttributes)
            {
                if (childURI == XmlSchema.Namespace)
                {
                    throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0);
                }

                XmlSchemaAttribute xsa = null;
                int AttributeType = -1;
                XmlSchemaAttribute returnedAttribute = null;    //this value will change to attributeReference if childURI!= parentURI
                XmlSchema xs = null;
                bool add = true;

                Debug.Assert(compiledAttributes != null); //AttributeUses is never null
                // First we need to look into the already compiled attributes 
                //   (they come from the schemaset which we got on input)
                // If there are none or we don't find it there, then we must search the list of attributes
                //   where we are going to add a new one (if it doesn't exist). 
                //   This is necessary to avoid adding duplicate attribute declarations.
                ICollection searchCollectionPrimary, searchCollectionSecondary;
                if (compiledAttributes.Count > 0) {
                    searchCollectionPrimary = compiledAttributes.Values;
                    searchCollectionSecondary = addLocation;
                }
                else {
                    searchCollectionPrimary = addLocation;
                    searchCollectionSecondary = null;
                }
                if (childURI == XmlReservedNs.NsXml)
                {
                    XmlSchemaAttribute attributeReference = null;
                    //see if the reference exists
                    attributeReference = FindAttributeRef(searchCollectionPrimary, localName, childURI);
                    if (attributeReference == null && searchCollectionSecondary != null) {
                        attributeReference = FindAttributeRef(searchCollectionSecondary, localName, childURI);
                    }
                    if (attributeReference == null)
                    {
                        attributeReference = new XmlSchemaAttribute();
                        attributeReference.RefName = new XmlQualifiedName(localName, childURI);
                        if (bCreatingNewType && this.Occurrence == InferenceOption.Restricted)
                        {
                            attributeReference.Use = XmlSchemaUse.Required;
                        }
                        else
                        {
                            attributeReference.Use = XmlSchemaUse.Optional;
                        }

                        addLocation.Add(attributeReference);
                    }
                    returnedAttribute = attributeReference;
                }
                else
                {
                    if (childURI.Length == 0)
                    {
                        xs = parentSchema;
                        add = false;
                    }
                    else if (childURI != null && !schemaSet.Contains(childURI))
                    {
                        /*if (parentSchema.AttributeFormDefault = XmlSchemaForm.Unqualified && childURI.Length == 0)
                    {
                        xs = parentSchema;
                        add = false;
                        break;
                    }*/
                        xs = new XmlSchema();
                        xs.AttributeFormDefault = XmlSchemaForm.Unqualified;
                        xs.ElementFormDefault = XmlSchemaForm.Qualified;
                        if (childURI.Length != 0)
                            xs.TargetNamespace = childURI;
                        //schemas.Add(childURI, xs);
                        this.schemaSet.Add(xs);
                        if (prefix.Length != 0 && String.Compare(prefix, "xml", StringComparison.OrdinalIgnoreCase) != 0)
                            NamespaceManager.AddNamespace(prefix, childURI);
                    }
                    else
                    {
                        ArrayList col = this.schemaSet.Schemas(childURI) as ArrayList;
                        if (col != null && col.Count > 0)
                        {
                            xs = col[0] as XmlSchema;
                        }

                    }
                    if (childURI.Length != 0) //
                    {
                        XmlSchemaAttribute attributeReference = null;
                        //see if the reference exists
                        attributeReference = FindAttributeRef(searchCollectionPrimary, localName, childURI);
                        if (attributeReference == null & searchCollectionSecondary != null) {
                            attributeReference = FindAttributeRef(searchCollectionSecondary, localName, childURI);
                        }
                        if (attributeReference == null)
                        {
                            attributeReference = new XmlSchemaAttribute();
                            attributeReference.RefName = new XmlQualifiedName(localName, childURI);
                            if (bCreatingNewType && this.Occurrence == InferenceOption.Restricted)
                            {
                                attributeReference.Use = XmlSchemaUse.Required;
                            }
                            else
                            {
                                attributeReference.Use = XmlSchemaUse.Optional;
                            }

                            addLocation.Add(attributeReference);
                        }
                        returnedAttribute = attributeReference;

                        //see if the attribute exists on the global level
                        xsa = FindAttribute(xs.Items, localName);
                        if (xsa == null)
                        {
                            xsa = new XmlSchemaAttribute();
                            xsa.Name = localName;
                            xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType);
                            xsa.LineNumber = AttributeType; //we use LineNumber to store flags of valid types
                            xs.Items.Add(xsa);

                        }
                        else
                        {
                            if (xsa.Parent == null)
                            {
                                AttributeType = xsa.LineNumber; // we use LineNumber to store flags of valid types
                            }
                            else
                            {
                                AttributeType = GetSchemaType(xsa.SchemaTypeName);
                                xsa.Parent = null;
                            }
                            xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType);
                            xsa.LineNumber = AttributeType; // we use LineNumber to store flags of valid types
                        }
                    }
                    else
                    {
                        xsa = FindAttribute(searchCollectionPrimary, localName);
                        if (xsa == null && searchCollectionSecondary != null) {
                            xsa = FindAttribute(searchCollectionSecondary, localName);
                        }
                        if (xsa == null)
                        {
                            xsa = new XmlSchemaAttribute();
                            xsa.Name = localName;
                            xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType);
                            xsa.LineNumber = AttributeType; // we use LineNumber to store flags of valid types
                            if (bCreatingNewType && this.Occurrence == InferenceOption.Restricted)
                                xsa.Use = XmlSchemaUse.Required;
                            else
                                xsa.Use = XmlSchemaUse.Optional;
                            addLocation.Add(xsa);
                            if (xs.AttributeFormDefault != XmlSchemaForm.Unqualified)
                            {
                                xsa.Form = XmlSchemaForm.Unqualified;
                            }
                        }
                        else
                        {
                            if (xsa.Parent == null)
                            {
                                AttributeType = xsa.LineNumber; // we use LineNumber to store flags of valid types
                            }
                            else
                            {
                                AttributeType = GetSchemaType(xsa.SchemaTypeName);
                                xsa.Parent = null;
                            }
                            xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType);
                            xsa.LineNumber = AttributeType; // we use LineNumber to store flags of valid types
                        }
                        returnedAttribute = xsa;
                    }
                }
                string nullString = null;
                if (add && childURI != parentSchema.TargetNamespace)
                {
                    for (int i = 0; i < parentSchema.Includes.Count; ++i)
                    {
                        XmlSchemaImport import = parentSchema.Includes[i] as XmlSchemaImport;
                        if (import == null)
                        {
                            continue;
                        }
                        if (import.Namespace == childURI)
                        {
                            add = false;
                        }
                    }
                    if (add)
                    {
                        XmlSchemaImport import = new XmlSchemaImport();
                        import.Schema = xs;
                        if (childURI.Length != 0)
                        {
                            nullString = childURI;
                        }
                        import.Namespace = nullString;
                        parentSchema.Includes.Add(import);
                    }
                }


                return returnedAttribute;
            }
Beispiel #19
0
        public static int ValidateAttributesResolved(
            XmlSchemaObjectTable attributesResolved,
            ValidationEventHandler h,
            XmlSchema schema,
            XmlSchemaObjectCollection attributes,
            XmlSchemaAnyAttribute anyAttribute,
            ref XmlSchemaAnyAttribute anyAttributeUse,
            XmlSchemaAttributeGroup redefined,
            bool skipEquivalent)
        {
            int errorCount = 0;

            if (anyAttribute != null && anyAttributeUse == null)
            {
                anyAttributeUse = anyAttribute;
            }

            ArrayList newAttrNames = new ArrayList();

            foreach (XmlSchemaObject xsobj in attributes)
            {
                XmlSchemaAttributeGroupRef grpRef = xsobj as XmlSchemaAttributeGroupRef;
                if (grpRef != null)
                {
                    // Resolve attributeGroup redefinition.
                    XmlSchemaAttributeGroup grp = null;
                    if (redefined != null && grpRef.RefName == redefined.QualifiedName)
                    {
                        grp = redefined;
                    }
                    else
                    {
                        grp = schema.FindAttributeGroup(grpRef.RefName);
                    }
                    // otherwise, it might be missing sub components.
                    if (grp == null)
                    {
                        if (!schema.missedSubComponents)                        // && schema.Schemas [grpRef.RefName.Namespace] != null)
                        {
                            grpRef.error(h, "Referenced attribute group " + grpRef.RefName + " was not found in the corresponding schema.");
                        }
                        continue;
                    }
                    if (grp.AttributeGroupRecursionCheck)
                    {
                        grp.error(h, "Attribute group recursion was found: " + grpRef.RefName);
                        continue;
                    }
                    try {
                        grp.AttributeGroupRecursionCheck = true;
                        errorCount += grp.Validate(h, schema);
                    } finally {
                        grp.AttributeGroupRecursionCheck = false;
                    }
                    if (grp.AnyAttributeUse != null)
                    {
                        if (anyAttribute == null)
                        {
                            anyAttributeUse = grp.AnyAttributeUse;
                        }
                    }
                    foreach (DictionaryEntry entry in grp.AttributeUses)
                    {
                        XmlSchemaAttribute attr = (XmlSchemaAttribute)entry.Value;
#if BUGGY_MS_COMPLIANT
                        if (attr.Use == XmlSchemaUse.Prohibited)
                        {
                            continue;
                        }
#endif
                        if (attr.RefName != null && attr.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !AreAttributesEqual(attr, attributesResolved [attr.RefName] as XmlSchemaAttribute)))
                        {
                            AddToTable(attributesResolved, attr, attr.RefName, h);
                        }
                        else if (!skipEquivalent || !AreAttributesEqual(attr, attributesResolved [attr.QualifiedName] as XmlSchemaAttribute))
                        {
                            AddToTable(attributesResolved, attr, attr.QualifiedName, h);
                        }
                    }
                }
                else
                {
                    XmlSchemaAttribute attr = xsobj as XmlSchemaAttribute;
                    if (attr != null)
                    {
                        errorCount += attr.Validate(h, schema);

                        if (newAttrNames.Contains(attr.QualifiedName))
                        {
                            attr.error(h, String.Format("Duplicate attributes was found for '{0}'", attr.QualifiedName));
                        }
                        newAttrNames.Add(attr.QualifiedName);

#if BUGGY_MS_COMPLIANT
                        if (attr.Use == XmlSchemaUse.Prohibited)
                        {
                            continue;
                        }
#endif
                        if (attr.RefName != null && attr.RefName != XmlQualifiedName.Empty && (!skipEquivalent || !AreAttributesEqual(attr, attributesResolved [attr.RefName] as XmlSchemaAttribute)))
                        {
                            AddToTable(attributesResolved, attr, attr.RefName, h);
                        }
                        else if (!skipEquivalent || !AreAttributesEqual(attr, attributesResolved [attr.QualifiedName] as XmlSchemaAttribute))
                        {
                            AddToTable(attributesResolved, attr, attr.QualifiedName, h);
                        }
                    }
                    else
                    {
                        if (anyAttribute == null)
                        {
                            anyAttributeUse = (XmlSchemaAnyAttribute)xsobj;
                            anyAttribute.Validate(h, schema);
                        }
                    }
                }
            }
            return(errorCount);
        }
 /// <summary>Initializes a new instance of the <see cref="T:System.Xml.Schema.XmlSchemaChoice" /> class.</summary>
 public XmlSchemaChoice()
 {
     this.items = new XmlSchemaObjectCollection();
 }
 internal abstract void SetItems(XmlSchemaObjectCollection newItems);
Beispiel #22
0
        internal virtual RestrictionFacets ConstructRestriction(DatatypeImplementation datatype, XmlSchemaObjectCollection facets, XmlNameTable nameTable)
        {
            RestrictionFacets restriction = new RestrictionFacets();
            FacetsCompiler    compiler    = new FacetsCompiler(datatype, restriction);

            for (int i = 0; i < facets.Count; i++)
            {
                XmlSchemaFacet source = (XmlSchemaFacet)facets[i];
                if (source.Value == null)
                {
                    throw new XmlSchemaException("Sch_InvalidFacet", source);
                }
                IXmlNamespaceResolver nsmgr = new SchemaNamespaceManager(source);
                switch (source.FacetType)
                {
                case FacetType.Length:
                    compiler.CompileLengthFacet(source);
                    break;

                case FacetType.MinLength:
                    compiler.CompileMinLengthFacet(source);
                    break;

                case FacetType.MaxLength:
                    compiler.CompileMaxLengthFacet(source);
                    break;

                case FacetType.Pattern:
                    compiler.CompilePatternFacet(source as XmlSchemaPatternFacet);
                    break;

                case FacetType.Whitespace:
                    compiler.CompileWhitespaceFacet(source);
                    break;

                case FacetType.Enumeration:
                    compiler.CompileEnumerationFacet(source, nsmgr, nameTable);
                    break;

                case FacetType.MinExclusive:
                    compiler.CompileMinExclusiveFacet(source);
                    break;

                case FacetType.MinInclusive:
                    compiler.CompileMinInclusiveFacet(source);
                    break;

                case FacetType.MaxExclusive:
                    compiler.CompileMaxExclusiveFacet(source);
                    break;

                case FacetType.MaxInclusive:
                    compiler.CompileMaxInclusiveFacet(source);
                    break;

                case FacetType.TotalDigits:
                    compiler.CompileTotalDigitsFacet(source);
                    break;

                case FacetType.FractionDigits:
                    compiler.CompileFractionDigitsFacet(source);
                    break;

                default:
                    throw new XmlSchemaException("Sch_UnknownFacet", source);
                }
            }
            compiler.FinishFacetCompile();
            compiler.CompileFacetCombinations();
            return(restriction);
        }
Beispiel #23
0
 private void Add(XmlSchemaObjectCollection collToAdd)
 {
     this.InnerList.InsertRange(0, collToAdd);
 }
Beispiel #24
0
 protected XmlSchemaGroupBase()
 {
     compiledItems = new XmlSchemaObjectCollection();
 }
Beispiel #25
0
            internal void ProcessAttributes(ref XmlSchemaElement xse, XmlSchemaType effectiveSchemaType, bool bCreatingNewType, XmlSchema parentSchema)
            {
                XmlSchemaObjectCollection attributesSeen = new XmlSchemaObjectCollection();
                XmlSchemaComplexType ct = effectiveSchemaType as XmlSchemaComplexType;
                
                Debug.Assert(xtr.NodeType == XmlNodeType.Attribute);
                do
                {
                    if (xtr.NamespaceURI == XmlSchema.Namespace)
                    {
                        throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0);
                    }

                    if (xtr.NamespaceURI == XmlReservedNs.NsXmlNs)
                    {
                        if (xtr.Prefix=="xmlns") 
                            NamespaceManager.AddNamespace(xtr.LocalName, xtr.Value);
                    }
                    else if (xtr.NamespaceURI == XmlReservedNs.NsXsi)
                    {
                        string localName = xtr.LocalName;
                        if (localName == "nil") 
                        {
                            xse.IsNillable = true;
                        }
                        else if (localName != "type" && localName != "schemaLocation" && localName != "noNamespaceSchemaLocation")
                        {
                            throw new XmlSchemaInferenceException(Res.Sch_NotXsiAttribute,localName);
                        }
                    }
                    else
                    {
                        if (ct == null || ct == XmlSchemaComplexType.AnyType)
                        {
                            ct = new XmlSchemaComplexType();
                            xse.SchemaType = ct;
                        }

                        XmlSchemaAttribute xsa=null;
                        //The earlier assumption of checking just schemaTypeName !Empty is not correct for schemas that are not generated by us, schemaTypeName can point to any complex type as well
                        //Check that it is a simple type by checking typeCode
                        //Switch to complex type simple content extension
                        if (effectiveSchemaType != null && effectiveSchemaType.Datatype != null && !xse.SchemaTypeName.IsEmpty)  
                        {
                            //type was previously simple type, now it will become complex with simple type extension
                            Debug.Assert(ct != null);
                            XmlSchemaSimpleContent sc = new XmlSchemaSimpleContent();
                            ct.ContentModel = sc;
                            XmlSchemaSimpleContentExtension sce = new XmlSchemaSimpleContentExtension();
                            sc.Content = sce;
                            sce.BaseTypeName = xse.SchemaTypeName;
                            sce.LineNumber = xse.LineNumber;
                            xse.LineNumber = 0;
                            xse.SchemaTypeName = XmlQualifiedName.Empty; //re-set the name
                        }
                        
                        Debug.Assert(ct != null); //either the user-defined type itself is a complex type or we switched from a simple type to a complex type
                        if (ct.ContentModel != null) 
                        {
                            XmlSchemaSimpleContentExtension sce = CheckSimpleContentExtension(ct);
                            Debug.Assert(sce != null);
                            xsa = AddAttribute(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, xtr.Value, bCreatingNewType, parentSchema, sce.Attributes, ct.AttributeUses);
                        } 
                        else //add atributes directly to complex type
                        {
                            xsa = AddAttribute(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, xtr.Value, bCreatingNewType, parentSchema, ct.Attributes, ct.AttributeUses);
                        }
                        if (xsa != null) {
                            attributesSeen.Add(xsa);
                        }
                    }
                    
                } while (xtr.MoveToNextAttribute());
                if (!bCreatingNewType)
                {   
                    //make attributes that did not appear this time optional
                    if (ct!=null) {
                        MakeExistingAttributesOptional(ct, attributesSeen);
                    }
                }
            }
Beispiel #26
0
 internal void MakeExistingAttributesOptional(XmlSchemaComplexType ct, XmlSchemaObjectCollection attributesInInstance) {
     if (ct == null)  {
         throw new XmlSchemaInferenceException(Res.SchInf_noct, 0, 0);
     }
     if (ct.ContentModel != null) {
         XmlSchemaSimpleContentExtension xssce = CheckSimpleContentExtension(ct);
         SwitchUseToOptional(xssce.Attributes, attributesInInstance);
     }
     else { //either <xs:attribute> as child of xs:complexType or the attributes are within the content model
         SwitchUseToOptional(ct.Attributes, attributesInInstance);
     }
 }
Beispiel #27
0
        internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle, ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            if (this == baseParticle)
            {
                return(true);
            }
            XmlSchemaElement xmlSchemaElement = baseParticle as XmlSchemaElement;

            if (xmlSchemaElement != null)
            {
                if (raiseError)
                {
                    base.error(h, "Invalid sequence paricle derivation.");
                }
                return(false);
            }
            XmlSchemaSequence xmlSchemaSequence = baseParticle as XmlSchemaSequence;

            if (xmlSchemaSequence != null)
            {
                return(this.ValidateOccurenceRangeOK(xmlSchemaSequence, h, schema, raiseError) && ((xmlSchemaSequence.ValidatedMinOccurs == 0m && xmlSchemaSequence.ValidatedMaxOccurs == 0m && base.ValidatedMinOccurs == 0m && base.ValidatedMaxOccurs == 0m) || base.ValidateRecurse(xmlSchemaSequence, h, schema, raiseError)));
            }
            XmlSchemaAll xmlSchemaAll = baseParticle as XmlSchemaAll;

            if (xmlSchemaAll != null)
            {
                XmlSchemaObjectCollection xmlSchemaObjectCollection = new XmlSchemaObjectCollection();
                for (int i = 0; i < this.Items.Count; i++)
                {
                    XmlSchemaElement xmlSchemaElement2 = this.Items[i] as XmlSchemaElement;
                    if (xmlSchemaElement2 == null)
                    {
                        if (raiseError)
                        {
                            base.error(h, "Invalid sequence particle derivation by restriction from all.");
                        }
                        return(false);
                    }
                    foreach (XmlSchemaObject xmlSchemaObject in xmlSchemaAll.Items)
                    {
                        XmlSchemaElement xmlSchemaElement3 = (XmlSchemaElement)xmlSchemaObject;
                        if (xmlSchemaElement3.QualifiedName == xmlSchemaElement2.QualifiedName)
                        {
                            if (xmlSchemaObjectCollection.Contains(xmlSchemaElement3))
                            {
                                if (raiseError)
                                {
                                    base.error(h, "Base element particle is mapped to the derived element particle in a sequence two or more times.");
                                }
                                return(false);
                            }
                            xmlSchemaObjectCollection.Add(xmlSchemaElement3);
                            if (!xmlSchemaElement2.ValidateDerivationByRestriction(xmlSchemaElement3, h, schema, raiseError))
                            {
                                return(false);
                            }
                        }
                    }
                }
                foreach (XmlSchemaObject xmlSchemaObject2 in xmlSchemaAll.Items)
                {
                    XmlSchemaElement xmlSchemaElement4 = (XmlSchemaElement)xmlSchemaObject2;
                    if (!xmlSchemaObjectCollection.Contains(xmlSchemaElement4) && !xmlSchemaElement4.ValidateIsEmptiable())
                    {
                        if (raiseError)
                        {
                            base.error(h, "In base -all- particle, mapping-skipped base element which is not emptiable was found.");
                        }
                        return(false);
                    }
                }
                return(true);
            }
            XmlSchemaAny xmlSchemaAny = baseParticle as XmlSchemaAny;

            if (xmlSchemaAny != null)
            {
                return(base.ValidateNSRecurseCheckCardinality(xmlSchemaAny, h, schema, raiseError));
            }
            XmlSchemaChoice xmlSchemaChoice = baseParticle as XmlSchemaChoice;

            return(xmlSchemaChoice == null || base.ValidateSeqRecurseMapSumCommon(xmlSchemaChoice, h, schema, false, true, raiseError));
        }
 private int CountGroupSelfReference(XmlSchemaObjectCollection items, XmlQualifiedName name, XmlSchemaGroup redefined)
 {
     int num = 0;
     for (int i = 0; i < items.Count; i++)
     {
         XmlSchemaGroupRef source = items[i] as XmlSchemaGroupRef;
         if (source != null)
         {
             if (source.RefName == name)
             {
                 source.Redefined = redefined;
                 if ((source.MinOccurs != 1M) || (source.MaxOccurs != 1M))
                 {
                     base.SendValidationEvent("Sch_MinMaxGroupRedefine", source);
                 }
                 num++;
             }
         }
         else if (items[i] is XmlSchemaGroupBase)
         {
             num += this.CountGroupSelfReference(((XmlSchemaGroupBase) items[i]).Items, name, redefined);
         }
         if (num > 1)
         {
             return num;
         }
     }
     return num;
 }
        void WriteSortedItems(XmlSchemaObjectCollection items) {
            if (items == null) return;

            ArrayList list = new ArrayList();
            for (int i = 0; i < items.Count; i++) {
                list.Add(items[i]);
            }
            list.Sort(new XmlSchemaObjectComparer());
            for (int i = 0; i < list.Count; i++) {
                Write3_XmlSchemaObject((XmlSchemaObject)list[i]);
            }
        }
 public XmlSchemaSimpleContentExtension()
 {
     baseTypeName = XmlQualifiedName.Empty;
     attributes   = new XmlSchemaObjectCollection();
 }
 private void CompileLocalAttributes(XmlSchemaComplexType baseType, XmlSchemaComplexType derivedType, XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, XmlSchemaDerivationMethod derivedBy)
 {
     XmlSchemaAnyAttribute b = (baseType != null) ? baseType.AttributeWildcard : null;
     for (int i = 0; i < attributes.Count; i++)
     {
         XmlSchemaAttribute xa = attributes[i] as XmlSchemaAttribute;
         if (xa != null)
         {
             if (xa.Use != XmlSchemaUse.Prohibited)
             {
                 this.CompileAttribute(xa);
             }
             if ((xa.Use != XmlSchemaUse.Prohibited) || (((xa.Use == XmlSchemaUse.Prohibited) && (derivedBy == XmlSchemaDerivationMethod.Restriction)) && (baseType != XmlSchemaComplexType.AnyType)))
             {
                 if (derivedType.AttributeUses[xa.QualifiedName] == null)
                 {
                     derivedType.AttributeUses.Add(xa.QualifiedName, xa);
                 }
                 else
                 {
                     base.SendValidationEvent("Sch_DupAttributeUse", xa.QualifiedName.ToString(), xa);
                 }
             }
             else
             {
                 base.SendValidationEvent("Sch_AttributeIgnored", xa.QualifiedName.ToString(), xa, XmlSeverityType.Warning);
             }
         }
         else
         {
             XmlSchemaAttributeGroupRef source = (XmlSchemaAttributeGroupRef) attributes[i];
             XmlSchemaAttributeGroup attributeGroup = (XmlSchemaAttributeGroup) this.schema.AttributeGroups[source.RefName];
             if (attributeGroup != null)
             {
                 this.CompileAttributeGroup(attributeGroup);
                 foreach (XmlSchemaAttribute attribute3 in attributeGroup.AttributeUses.Values)
                 {
                     if ((attribute3.Use != XmlSchemaUse.Prohibited) || (((attribute3.Use == XmlSchemaUse.Prohibited) && (derivedBy == XmlSchemaDerivationMethod.Restriction)) && (baseType != XmlSchemaComplexType.AnyType)))
                     {
                         if (derivedType.AttributeUses[attribute3.QualifiedName] == null)
                         {
                             derivedType.AttributeUses.Add(attribute3.QualifiedName, attribute3);
                         }
                         else
                         {
                             base.SendValidationEvent("Sch_DupAttributeUse", attribute3.QualifiedName.ToString(), source);
                         }
                     }
                     else
                     {
                         base.SendValidationEvent("Sch_AttributeIgnored", attribute3.QualifiedName.ToString(), attribute3, XmlSeverityType.Warning);
                     }
                 }
                 anyAttribute = this.CompileAnyAttributeIntersection(anyAttribute, attributeGroup.AttributeWildcard);
             }
             else
             {
                 base.SendValidationEvent("Sch_UndefAttributeGroupRef", source.RefName.ToString(), source);
             }
         }
     }
     if (baseType != null)
     {
         if (derivedBy == XmlSchemaDerivationMethod.Extension)
         {
             derivedType.SetAttributeWildcard(this.CompileAnyAttributeUnion(anyAttribute, b));
             foreach (XmlSchemaAttribute attribute4 in baseType.AttributeUses.Values)
             {
                 XmlSchemaAttribute attribute5 = (XmlSchemaAttribute) derivedType.AttributeUses[attribute4.QualifiedName];
                 if (attribute5 != null)
                 {
                     if ((attribute5.AttributeSchemaType != attribute4.AttributeSchemaType) || (attribute4.Use == XmlSchemaUse.Prohibited))
                     {
                         base.SendValidationEvent("Sch_InvalidAttributeExtension", attribute5);
                     }
                 }
                 else
                 {
                     derivedType.AttributeUses.Add(attribute4.QualifiedName, attribute4);
                 }
             }
         }
         else
         {
             if ((anyAttribute != null) && ((b == null) || !XmlSchemaAnyAttribute.IsSubset(anyAttribute, b)))
             {
                 base.SendValidationEvent("Sch_InvalidAnyAttributeRestriction", derivedType);
             }
             else
             {
                 derivedType.SetAttributeWildcard(anyAttribute);
             }
             foreach (XmlSchemaAttribute attribute6 in baseType.AttributeUses.Values)
             {
                 XmlSchemaAttribute attribute7 = (XmlSchemaAttribute) derivedType.AttributeUses[attribute6.QualifiedName];
                 if (attribute7 == null)
                 {
                     derivedType.AttributeUses.Add(attribute6.QualifiedName, attribute6);
                 }
                 else if ((attribute6.Use == XmlSchemaUse.Prohibited) && (attribute7.Use != XmlSchemaUse.Prohibited))
                 {
                     base.SendValidationEvent("Sch_AttributeRestrictionProhibited", attribute7);
                 }
                 else if ((attribute7.Use != XmlSchemaUse.Prohibited) && (((attribute6.AttributeSchemaType == null) || (attribute7.AttributeSchemaType == null)) || !XmlSchemaType.IsDerivedFrom(attribute7.AttributeSchemaType, attribute6.AttributeSchemaType, XmlSchemaDerivationMethod.Empty)))
                 {
                     base.SendValidationEvent("Sch_AttributeRestrictionInvalid", attribute7);
                 }
             }
             foreach (XmlSchemaAttribute attribute8 in derivedType.AttributeUses.Values)
             {
                 if ((((XmlSchemaAttribute) baseType.AttributeUses[attribute8.QualifiedName]) == null) && ((b == null) || !b.Allows(attribute8.QualifiedName)))
                 {
                     base.SendValidationEvent("Sch_AttributeRestrictionInvalidFromWildcard", attribute8);
                 }
             }
         }
     }
     else
     {
         derivedType.SetAttributeWildcard(anyAttribute);
     }
 }
 private static void CleanupAttributes(XmlSchemaObjectCollection attributes)
 {
     for (int i = 0; i < attributes.Count; i++)
     {
         XmlSchemaAttribute attribute = attributes[i] as XmlSchemaAttribute;
         if (attribute != null)
         {
             CleanupAttribute(attribute);
         }
     }
 }
 public XmlSchemaComplexContentExtension()
 {
     attributes   = new XmlSchemaObjectCollection();
     baseTypeName = XmlQualifiedName.Empty;
 }
 internal virtual void OnAdd(XmlSchemaObjectCollection container, object?item)
 {
 }
Beispiel #35
0
//		ArrayList compiledFields;

        public XmlSchemaIdentityConstraint()
        {
            fields = new XmlSchemaObjectCollection();
            qName  = XmlQualifiedName.Empty;
        }
Beispiel #36
0
        private void InferAttributes(Element el, string ns, bool isNew)
        {
            // Now this element is going to have complexType.
            // It currently not, then we have to replace it.
            ComplexType ct      = null;
            SOMList     attList = null;
            Hashtable   table   = null;

            do
            {
                switch (source.NamespaceURI)
                {
                case NamespaceXml:
                    if (schemas.Schemas(
                            NamespaceXml).Count == 0)
                    {
                        IncludeXmlAttributes();
                    }
                    break;

                case XmlSchema.InstanceNamespace:
                    if (source.LocalName == "nil")
                    {
                        el.IsNillable = true;
                    }
                    // all other xsi:* atts are ignored
                    continue;

                case NamespaceXmlns:
                    continue;
                }
                if (ct == null)
                {
                    ct      = ToComplexType(el);
                    attList = GetAttributes(ct);
                    table   = CollectAttrTable(attList);
                }
                QName attrName = new QName(
                    source.LocalName, source.NamespaceURI);
                Attr attr = table [attrName] as Attr;
                if (attr == null)
                {
                    attList.Add(InferNewAttribute(
                                    attrName, isNew, ns));
                }
                else
                {
                    table.Remove(attrName);
                    if (attr.RefName != null &&
                        attr.RefName != QName.Empty)
                    {
                        continue;                         // just a reference
                    }
                    InferMergedAttribute(attr);
                }
            } while (source.MoveToNextAttribute());

            // mark all attr definitions that did not appear
            // as optional.
            if (table != null)
            {
                foreach (Attr attr in table.Values)
                {
                    attr.Use = Use.Optional;
                }
            }
        }
Beispiel #37
0
 internal XmlSchemaDatatype DeriveByRestriction(XmlSchemaObjectCollection facets, XmlNameTable nameTable)
 {
     return(((DatatypeImplementation)this).DeriveByRestriction(facets, nameTable));
 }
 internal static XmlQualifiedName NameOf(XmlSchemaObjectCollection items) {
     ArrayList list = new ArrayList();
     
     for (int i = 0; i < items.Count; i++) {
         list.Add(NameOf(items[i]));
     }
     list.Sort(new QNameComparer());
     return (XmlQualifiedName)list[0];
 }
        // 3.14.6 Derivation Valid (RestrictionSimple)
        internal void ValidateDerivationValid(object baseType, XmlSchemaObjectCollection facets,
                                              ValidationEventHandler h, XmlSchema schema)
        {
            // TODO
            XmlSchemaSimpleType baseSimpleType = baseType as XmlSchemaSimpleType;

            switch (this.Variety)
            {
            // 1. atomic type
            case XmlSchemaDerivationMethod.Restriction:
                // 1.1
                if (baseSimpleType != null && baseSimpleType.resolvedDerivedBy != XmlSchemaDerivationMethod.Restriction)
                {
                    error(h, "Base schema type is not either atomic type or primitive type.");
                }
                // 1.2
                if (baseSimpleType != null &&
                    (baseSimpleType.FinalResolved & XmlSchemaDerivationMethod.Restriction) != 0)
                {
                    error(h, "Derivation by restriction is prohibited by the base simple type.");
                }
                // TODO: 1.3 facet restriction valid.
                break;

            case XmlSchemaDerivationMethod.List:
                /*
                 * XmlSchemaSimpleTypeList thisList = Content as XmlSchemaSimpleTypeList;
                 * // 2.1 item list type not allowed
                 * if (baseSimpleType != null && baseSimpleType.resolvedDerivedBy == XmlSchemaDerivationMethod.List)
                 *      error (h, "Base list schema type is not allowed.");
                 * XmlSchemaSimpleTypeUnion baseUnion = baseSimpleType.Content as XmlSchemaSimpleTypeUnion;
                 * if (baseUnion != null) {
                 *      bool errorFound = false;
                 *      foreach (object memberType in baseUnion.ValidatedTypes) {
                 *              XmlSchemaSimpleType memberST = memberType as XmlSchemaSimpleType;
                 *              if (memberST != null && memberST.resolvedDerivedBy == XmlSchemaDerivationMethod.List)
                 *                      errorFound = true;
                 *      }
                 *      if (errorFound)
                 *              error (h, "Base union schema type should not contain list types.");
                 * }
                 */
                // 2.2 facets limited
                if (facets != null)
                {
                    foreach (XmlSchemaFacet facet in facets)
                    {
                        if (facet is XmlSchemaLengthFacet ||
                            facet is XmlSchemaMaxLengthFacet ||
                            facet is XmlSchemaMinLengthFacet ||
                            facet is XmlSchemaEnumerationFacet ||
                            facet is XmlSchemaPatternFacet)
                        {
                            continue;
                        }
                        else
                        {
                            error(h, "Not allowed facet was found on this simple type which derives list type.");
                        }
                    }
                }
                break;

            case XmlSchemaDerivationMethod.Union:
                // 3.1

                // 3.2
                if (facets != null)
                {
                    foreach (XmlSchemaFacet facet in facets)
                    {
                        if (facet is XmlSchemaEnumerationFacet ||
                            facet is XmlSchemaPatternFacet)
                        {
                            continue;
                        }
                        else
                        {
                            error(h, "Not allowed facet was found on this simple type which derives list type.");
                        }
                    }
                }
                break;
            }
        }
        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);
                }
            }
        }
 internal virtual void OnRemove(XmlSchemaObjectCollection container, object item)
 {
 }
 private int GetMappingParticle(XmlSchemaParticle particle, XmlSchemaObjectCollection collection)
 {
     for (int i = 0; i < collection.Count; i++)
     {
         if (this.IsValidRestriction(particle, (XmlSchemaParticle) collection[i]))
         {
             return i;
         }
     }
     return -1;
 }
 internal virtual void OnClear(XmlSchemaObjectCollection container)
 {
 }
Beispiel #44
0
        //Compile-time Facet Checking
        internal virtual RestrictionFacets ConstructRestriction(DatatypeImplementation datatype, XmlSchemaObjectCollection facets, XmlNameTable nameTable) {
            //Datatype is the type on which this method is called
            RestrictionFacets derivedRestriction = new RestrictionFacets();
            FacetsCompiler facetCompiler = new FacetsCompiler(datatype, derivedRestriction);

            for (int i = 0; i < facets.Count; ++i) {
                XmlSchemaFacet facet = (XmlSchemaFacet)facets[i];
                if (facet.Value == null) {
                    throw new XmlSchemaException(Res.Sch_InvalidFacet, facet);
                }
                IXmlNamespaceResolver nsmgr = new SchemaNamespaceManager(facet);
                switch(facet.FacetType) {
                    case FacetType.Length:
                        facetCompiler.CompileLengthFacet(facet);
                    break;

                    case FacetType.MinLength:
                        facetCompiler.CompileMinLengthFacet(facet);
                    break;

                    case FacetType.MaxLength:
                        facetCompiler.CompileMaxLengthFacet(facet);
                    break;
    
                    case FacetType.Pattern:
                        facetCompiler.CompilePatternFacet(facet as XmlSchemaPatternFacet);
                    break;

                    case FacetType.Enumeration:
                        facetCompiler.CompileEnumerationFacet(facet, nsmgr, nameTable);                        
                    break;

                    case FacetType.Whitespace:
                        facetCompiler.CompileWhitespaceFacet(facet);
                    break;

                    case FacetType.MinInclusive:
                        facetCompiler.CompileMinInclusiveFacet(facet);
                    break;

                    case FacetType.MinExclusive:
                        facetCompiler.CompileMinExclusiveFacet(facet);
                    break;

                    case FacetType.MaxInclusive:
                        facetCompiler.CompileMaxInclusiveFacet(facet);
                    break;

                    case FacetType.MaxExclusive:
                        facetCompiler.CompileMaxExclusiveFacet(facet);
                    break;

                    case FacetType.TotalDigits:
                        facetCompiler.CompileTotalDigitsFacet(facet);
                    break;

                    case FacetType.FractionDigits:
                        facetCompiler.CompileFractionDigitsFacet(facet);
                    break;

                    default:
                        throw new XmlSchemaException(Res.Sch_UnknownFacet, facet);
                }
            }
            facetCompiler.FinishFacetCompile();
            facetCompiler.CompileFacetCombinations();
            return derivedRestriction;
        }
Beispiel #45
0
 /// <summary>Initializes a new instance of the <see cref="T:System.Xml.Schema.XmlSchemaAttributeGroup" /> class.</summary>
 public XmlSchemaAttributeGroup()
 {
     this.attributes    = new XmlSchemaObjectCollection();
     this.qualifiedName = XmlQualifiedName.Empty;
 }
 internal override void SetItems(XmlSchemaObjectCollection newItems)
 {
     this.items = newItems;
 }
 internal abstract XmlSchemaDatatype DeriveByRestriction(XmlSchemaObjectCollection facets, XmlNameTable nameTable, XmlSchemaType schemaType);
 internal XmlSchemaObjectCollection Clone() {
     XmlSchemaObjectCollection coll = new XmlSchemaObjectCollection();
     coll.Add(this);
     return coll;
 }
Beispiel #49
0
        internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle,
                                                               ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            if (this == baseParticle) // quick check
            {
                return(true);
            }

            XmlSchemaElement el = baseParticle as XmlSchemaElement;

            if (el != null)
            {
                // Forbidden
                if (raiseError)
                {
                    error(h, "Invalid sequence paricle derivation.");
                }
                return(false);
            }

            XmlSchemaSequence seq = baseParticle as XmlSchemaSequence;

            if (seq != null)
            {
                // Recurse
                if (!ValidateOccurenceRangeOK(seq, h, schema, raiseError))
                {
                    return(false);
                }

                // If it is totally optional, then ignore their contents.
                if (seq.ValidatedMinOccurs == 0 && seq.ValidatedMaxOccurs == 0 &&
                    this.ValidatedMinOccurs == 0 && this.ValidatedMaxOccurs == 0)
                {
                    return(true);
                }
                return(ValidateRecurse(seq, h, schema, raiseError));
            }

            XmlSchemaAll all = baseParticle as XmlSchemaAll;

            if (all != null)
            {
                // RecurseUnordered
                XmlSchemaObjectCollection already = new XmlSchemaObjectCollection();
                for (int i = 0; i < this.Items.Count; i++)
                {
                    XmlSchemaElement de = this.Items [i] as XmlSchemaElement;
                    if (de == null)
                    {
                        if (raiseError)
                        {
                            error(h, "Invalid sequence particle derivation by restriction from all.");
                        }
                        return(false);
                    }
                    foreach (XmlSchemaElement e in all.Items)
                    {
                        if (e.QualifiedName == de.QualifiedName)
                        {
                            if (already.Contains(e))
                            {
                                if (raiseError)
                                {
                                    error(h, "Base element particle is mapped to the derived element particle in a sequence two or more times.");
                                }
                                return(false);
                            }
                            else
                            {
                                already.Add(e);
                                if (!de.ValidateDerivationByRestriction(e, h, schema, raiseError))
                                {
                                    return(false);
                                }
                            }
                        }
                    }
                }
                foreach (XmlSchemaElement e in all.Items)
                {
                    if (!already.Contains(e))
                    {
                        if (!e.ValidateIsEmptiable())
                        {
                            if (raiseError)
                            {
                                error(h, "In base -all- particle, mapping-skipped base element which is not emptiable was found.");
                            }
                            return(false);
                        }
                    }
                }
                return(true);
            }
            XmlSchemaAny any = baseParticle as XmlSchemaAny;

            if (any != null)
            {
                // NSRecurseCheckCardinality
                return(ValidateNSRecurseCheckCardinality(any, h, schema, raiseError));
            }
            XmlSchemaChoice choice = baseParticle as XmlSchemaChoice;

            if (choice != null)
            {
                // MapAndSum
                // In fact it is not Recurse, but it looks almost common.
                return(ValidateSeqRecurseMapSumCommon(choice, h, schema, false, true, raiseError));
            }
            return(true);
        }
Beispiel #50
0
            /// <summary>
            /// Verifies that the current element has its corresponding element in the sequence and order is the same.
            /// If the order is not the same, it changes the particle from Sequence to Sequence with Choice.
            /// If there is more elements of the same kind in the sequence, sets maxOccurs to unbounded
            /// </summary>
            /// <param name="bCreatingNewType">True if this is a new type. This is important for setting minOccurs=0 for elements that did not exist in a particle.</param>
            /// <param name="xtr">text reader positioned to the current element</param>
            /// <param name="ct">complex type with Sequence or Choice Particle</param>
            /// <param name="lastUsedSeqItem">ordinal number in the sequence to indicate current sequence position</param>
            /// <param name="itemsMadeOptional">hashtable of elements with minOccurs changed to 0 in order to satisfy sequence requirements. These elements will be rolled back if Sequence becomes Sequence of Choice.</param>
            /// <param name="bParticleChanged">This indicates to the caller if Sequence was changed to Choice</param>
            internal XmlSchemaElement FindMatchingElement(bool bCreatingNewType, XmlReader xtr,XmlSchemaComplexType ct, ref int lastUsedSeqItem, ref bool bParticleChanged, XmlSchema parentSchema, bool setMaxoccurs)
            {
                if (xtr.NamespaceURI == XmlSchema.Namespace)
                {
                    throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0);
                }

                bool bItemNotUsedYet = ((lastUsedSeqItem == -1)? true: false);
                XmlSchemaObjectCollection minOccursCandidates = new XmlSchemaObjectCollection(); //elements that are skipped in the sequence and need minOccurs modified.
                if (ct.Particle.GetType() == typeof (XmlSchemaSequence))
                {   
                    string childURI = xtr.NamespaceURI;
                    if (childURI.Length == 0) 
                    {
                        childURI = null;
                    }
                    XmlSchemaSequence xss = (XmlSchemaSequence) ct.Particle;
                    if (xss.Items.Count < 1 && !bCreatingNewType) 
                    {
                        lastUsedSeqItem = 0;
                        XmlSchemaElement e = AddElement(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, parentSchema, xss.Items,-1);
                        e.MinOccurs = 0;
                        return e;
                    }
                    if (xss.Items[0].GetType() == typeof (XmlSchemaChoice))
                    {   // <sequence minOccurs="0" maxOccurs="unbounded"><choice><element>...</choice></sequence>
                        XmlSchemaChoice xsch = (XmlSchemaChoice) xss.Items[0];
                        for (int i = 0; i < xsch.Items.Count; ++i)
                        {
                            XmlSchemaElement el = xsch.Items[i] as XmlSchemaElement;
                            if (el == null) 
                            {
                                throw new XmlSchemaInferenceException(Res.SchInf_UnknownParticle, 0, 0);
                            }
                            if ((el.Name == xtr.LocalName) &&( parentSchema.TargetNamespace == childURI))
                            {   // element is in the same namespace
                                InferElement(el, false, parentSchema);
                                SetMinMaxOccurs(el, setMaxoccurs);
                                return el;
                            }
                            else if ((el.RefName.Name == xtr.LocalName) && (el.RefName.Namespace == xtr.NamespaceURI))
                            {
                                XmlSchemaElement referencedElement = FindGlobalElement(childURI, xtr.LocalName, out parentSchema);
                                InferElement(referencedElement, false, parentSchema);
                                SetMinMaxOccurs(el, setMaxoccurs);
                                return referencedElement;
                            }
                        }
                        XmlSchemaElement subElement = AddElement(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, parentSchema, xsch.Items,-1);
                        return subElement;
                    } 
                    else
                    {   //this should be sequence of elements
                        int iSeqItem = 0;   //iterator through schema sequence items
                        if (lastUsedSeqItem >= 0)
                            iSeqItem = lastUsedSeqItem;
                        XmlSchemaParticle particle = xss.Items[iSeqItem] as XmlSchemaParticle;
                        XmlSchemaElement el = particle as XmlSchemaElement;
                        if (el == null)
                        {
                            throw new XmlSchemaInferenceException(Res.SchInf_UnknownParticle, 0, 0);
                        }
                        if (el.Name == xtr.LocalName && parentSchema.TargetNamespace == childURI)
                        {
                            if (!bItemNotUsedYet)   //read: if item was already used one or more times
                                el.MaxOccurs = decimal.MaxValue;    //set it to unbounded
                            lastUsedSeqItem = iSeqItem;
                            InferElement(el, false, parentSchema);
                            SetMinMaxOccurs(el, false);
                            return el;
                        } 
                        else if (el.RefName.Name == xtr.LocalName && el.RefName.Namespace == xtr.NamespaceURI)
                        {
                            if (!bItemNotUsedYet)   //read: if item was already used one or more times
                                el.MaxOccurs = decimal.MaxValue;    //set it to unbounded
                            lastUsedSeqItem = iSeqItem;
                            XmlSchemaElement referencedElement = FindGlobalElement(childURI, xtr.LocalName, out parentSchema);
                            InferElement(referencedElement, false, parentSchema);
                            SetMinMaxOccurs(el, false);
                            return el;
                        }
                        if (bItemNotUsedYet && el.MinOccurs!=decimal.Zero)
                            minOccursCandidates.Add(el);
                        iSeqItem++;
                        while (iSeqItem < xss.Items.Count)
                        {
                            particle = xss.Items[iSeqItem] as XmlSchemaParticle;
                            el = particle as XmlSchemaElement;
                            if (el == null)
                            {
                                throw new XmlSchemaInferenceException(Res.SchInf_UnknownParticle, 0, 0);
                            }
                            if (el.Name == xtr.LocalName && parentSchema.TargetNamespace == childURI)
                            {
                                lastUsedSeqItem = iSeqItem;
                                for (int i = 0; i < minOccursCandidates.Count; ++i)
                                {
                                    ((XmlSchemaElement) minOccursCandidates[i]).MinOccurs = decimal.Zero;
                                }
                                InferElement(el, false, parentSchema);
                                SetMinMaxOccurs(el, setMaxoccurs);
                                return el;
                            } 
                            else if (el.RefName.Name == xtr.LocalName && el.RefName.Namespace == xtr.NamespaceURI)
                            {
                                lastUsedSeqItem = iSeqItem;
                                for (int i = 0; i < minOccursCandidates.Count; ++i)
                                {
                                    ((XmlSchemaElement) minOccursCandidates[i]).MinOccurs = decimal.Zero;
                                }
                                XmlSchemaElement referencedElement = FindGlobalElement(childURI, xtr.LocalName, out parentSchema);
                                InferElement(referencedElement, false, parentSchema);
                                SetMinMaxOccurs(el, setMaxoccurs);
                                return referencedElement;
                            }
                        

                            minOccursCandidates.Add(el);
                            iSeqItem++;
                        }

                        //element not found in the sequence order, if it is found out of order change Sequence of elements to Sequence of Choices otherwise insert into sequence as optional
                        XmlSchemaElement subElement = null;
                        XmlSchemaElement actualElement = null;
                        //
        
                        if (parentSchema.TargetNamespace == childURI) 
                        {
                            subElement = FindElement(xss.Items, xtr.LocalName);
                            actualElement = subElement;
                        }
                        else 
                        {
                            subElement = FindElementRef(xss.Items, xtr.LocalName, xtr.NamespaceURI);
                            if (subElement != null) 
                            {
                                actualElement = FindGlobalElement(childURI, xtr.LocalName, out parentSchema);
                            }
                        }
                        if (null != subElement) 
                        {
                            XmlSchemaChoice xsc = new XmlSchemaChoice();
                            xsc.MaxOccurs = decimal.MaxValue;
                            SetMinMaxOccurs(subElement, setMaxoccurs);
                            InferElement(actualElement, false, parentSchema);
                            for (int i = 0; i < xss.Items.Count; ++i)
                            {
                                xsc.Items.Add(CreateNewElementforChoice((XmlSchemaElement) xss.Items[i]));
                            }
                            xss.Items.Clear();
                            xss.Items.Add(xsc);
                            return subElement;
                        }
                        else
                        {
                            subElement = AddElement(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, parentSchema, xss.Items, ++lastUsedSeqItem);
                            if (!bCreatingNewType)
                                subElement.MinOccurs = decimal.Zero;
                            return subElement;
                        }
                    }
                }
                else
                {
                    throw new XmlSchemaInferenceException(Res.SchInf_noseq, 0, 0);
                }
            
            }
Beispiel #51
0
 public XmlSchemaSequence()
 {
     items = new XmlSchemaObjectCollection();
 }
Beispiel #52
0
 internal XmlSchemaElement FindElementRef(XmlSchemaObjectCollection elements, string elementName, string nsURI)
 {
     for (int i = 0; i < elements.Count; ++i)
     {
         XmlSchemaElement xse = elements[i] as XmlSchemaElement;
         if (xse != null && xse.RefName != null)
         {
             if (xse.RefName.Name == elementName && xse.RefName.Namespace == nsURI)
             {
                 return xse;
             }
         }
     }
     return null;
 }
Beispiel #53
0
 internal override void SetItems(XmlSchemaObjectCollection newItems)
 {
     _items = newItems;
 }
Beispiel #54
0
 private void SwitchUseToOptional(XmlSchemaObjectCollection attributes, XmlSchemaObjectCollection attributesInInstance) {
     for (int i = 0; i < attributes.Count; ++i)
     {
         XmlSchemaAttribute attr = attributes[i] as XmlSchemaAttribute;
         if (attr != null) {
             if (attributesInInstance != null) {
                 if (attr.RefName.Name.Length == 0) { //If the attribute is not present in this instance, make it optional
                     if (null == FindAttribute(attributesInInstance, attr.Name)) {
                         attr.Use = XmlSchemaUse.Optional;
                     }
                 }
                 else {
                     if (null == FindAttributeRef(attributesInInstance, attr.RefName.Name, attr.RefName.Namespace)) {
                         attr.Use = XmlSchemaUse.Optional;
                     }
                 }
             }
             else {
                 attr.Use = XmlSchemaUse.Optional;
             }
         }
     }
 }
 internal void SetAttributes(XmlSchemaObjectCollection newAttributes)
 {
     _attributes = newAttributes;
 }
Beispiel #56
0
            private XmlSchemaElement AddElement(string localName, string prefix, string childURI, XmlSchema parentSchema, XmlSchemaObjectCollection addLocation, int positionWithinCollection)
            {
                if (childURI == XmlSchema.Namespace)
                {
                    throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0);
                }

                XmlSchemaElement xse = null;
                XmlSchemaElement returnedElement = xse; //this value will change to elementReference if childURI!= parentURI
                XmlSchema xs = null;
                bool bCreatingNewType = true;
                if (childURI == String.Empty) 
                {
                    childURI = null;
                }
                // The new element belongs to the same ns as parent and addlocation is not null
                if (parentSchema != null && childURI == parentSchema.TargetNamespace) 
                {
                    xse = new XmlSchemaElement();
                    xse.Name = localName;
                    xs = parentSchema;
                    if (xs.ElementFormDefault != XmlSchemaForm.Qualified && addLocation != null) 
                    {
                        xse.Form = XmlSchemaForm.Qualified;
                    }
                }
                else if (schemaSet.Contains(childURI))
                {
                    xse = this.FindGlobalElement(childURI, localName, out xs);
                    if (xse == null) 
                    {
                        ArrayList col = this.schemaSet.Schemas(childURI)as ArrayList;
                        if (col != null && col.Count > 0 ) 
                        {
                            xs = col[0] as XmlSchema;
                        }
                        xse = new XmlSchemaElement();
                        xse.Name = localName;
                        xs.Items.Add(xse);
                    }
                    else
                        bCreatingNewType = false;               

                }
                else
                {
                    xs = CreateXmlSchema(childURI);
                    if (prefix.Length!=0)
                        NamespaceManager.AddNamespace(prefix, childURI);
                    xse=new XmlSchemaElement();
                    xse.Name = localName;
                    xs.Items.Add(xse);  //add global element declaration only when creating new schema
                }
                if (parentSchema == null) 
                {
                    parentSchema = xs;
                    this.rootSchema = parentSchema;
                }

                if (childURI != parentSchema.TargetNamespace ) 
                {
                    bool add = true;

                    for (int i = 0; i < parentSchema.Includes.Count; ++i)
                    {
                        XmlSchemaImport import = parentSchema.Includes[i] as XmlSchemaImport;
                        if (import == null) 
                        {
                            continue;
                        }
                        //Debug.WriteLine(import.Schema.TargetNamespace);
                     
                        if (import.Namespace == childURI) 
                        {
                            add = false;
                        }
                    }
                    if (add) 
                    {
                        XmlSchemaImport import = new XmlSchemaImport();
                        import.Schema = xs;
                        import.Namespace = childURI;
                        parentSchema.Includes.Add(import);
                    }      
                }
                returnedElement = xse;
                if (addLocation != null)
                {
                    if (childURI == parentSchema.TargetNamespace )
                    {
                        if (this.Occurrence == InferenceOption.Relaxed /*&& parentSchema.Items != addLocation*/) 
                        {
                            xse.MinOccurs = 0;
                        }
                        if (positionWithinCollection == -1) 
                        {
                            positionWithinCollection = addLocation.Add(xse);
                        }
                        else 
                        {
                            addLocation.Insert(positionWithinCollection, xse);
                        }
                    }
                    else
                    {
                        XmlSchemaElement elementReference = new XmlSchemaElement();
                        elementReference.RefName = new XmlQualifiedName(localName, childURI);
                        if (this.Occurrence == InferenceOption.Relaxed) 
                        {
                            elementReference.MinOccurs = 0;
                        }
                        if (positionWithinCollection == -1) 
                        {
                            positionWithinCollection = addLocation.Add(elementReference);
                        }
                        else 
                        {
                            addLocation.Insert(positionWithinCollection, elementReference);
                        }
                        returnedElement = elementReference;
                       /* if (childURI == XmlSchema.Namespace) 
                        {
                            schemaList.Add(new ReplaceList(addLocation, positionWithinCollection));
                        }*/
                    }
                }
           

                InferElement(xse, bCreatingNewType, xs);
            
                return returnedElement;
            }
Beispiel #57
0
 public XmlSchemaAnnotation()
 {
     items = new XmlSchemaObjectCollection();
 }
 private void PreprocessAttributes(XmlSchemaObjectCollection attributes, XmlSchemaAnyAttribute anyAttribute, XmlSchemaObject parent)
 {
     for (int i = 0; i < attributes.Count; i++)
     {
         this.SetParent(attributes[i], parent);
         XmlSchemaAttribute attribute = attributes[i] as XmlSchemaAttribute;
         if (attribute != null)
         {
             this.PreprocessLocalAttribute(attribute);
         }
         else
         {
             XmlSchemaAttributeGroupRef source = (XmlSchemaAttributeGroupRef) attributes[i];
             if (source.RefName.IsEmpty)
             {
                 base.SendValidationEvent("Sch_MissAttribute", "ref", source);
             }
             else
             {
                 this.ValidateQNameAttribute(source, "ref", source.RefName);
             }
             this.PreprocessAnnotation(attributes[i]);
             this.ValidateIdAttribute(attributes[i]);
         }
     }
     if (anyAttribute != null)
     {
         try
         {
             this.SetParent(anyAttribute, parent);
             this.PreprocessAnnotation(anyAttribute);
             anyAttribute.BuildNamespaceList(this.targetNamespace);
         }
         catch (FormatException exception)
         {
             base.SendValidationEvent("Sch_InvalidAnyDetailed", new string[] { exception.Message }, exception, anyAttribute);
         }
         this.ValidateIdAttribute(anyAttribute);
     }
 }
 /// <summary>Initializes a new instance of the <see cref="T:System.Xml.Schema.XmlSchemaSimpleTypeUnion" /> class.</summary>
 public XmlSchemaSimpleTypeUnion()
 {
     this.baseTypes = new XmlSchemaObjectCollection();
 }