Inheritance: XmlSchemaAnnotated
コード例 #1
0
 internal override int Validate(ValidationEventHandler h, XmlSchema schema)
 {
     if (base.IsValidated(schema.ValidationId))
     {
         return(this.errorCount);
     }
     this.referencedGroup = (schema.Groups[this.RefName] as XmlSchemaGroup);
     if (this.referencedGroup == null)
     {
         if (!schema.IsNamespaceAbsent(this.RefName.Namespace))
         {
             base.error(h, "Referenced group " + this.RefName + " was not found in the corresponding schema.");
         }
     }
     else if (this.referencedGroup.Particle is XmlSchemaAll && base.ValidatedMaxOccurs != 1m)
     {
         base.error(h, "Group reference to -all- particle must have schema component {maxOccurs}=1.");
     }
     if (this.TargetGroup != null)
     {
         this.TargetGroup.Validate(h, schema);
     }
     this.ValidationId = schema.ValidationId;
     return(this.errorCount);
 }
コード例 #2
0
        bool busy; // only for avoiding infinite loop on illegal recursion cases.
        internal override XmlSchemaParticle GetOptimizedParticle(bool isTop)
        {
            if (busy)
            {
                return(XmlSchemaParticle.Empty);
            }
            if (OptimizedParticle != null)
            {
                return(OptimizedParticle);
            }
            busy = true;
            XmlSchemaGroup g = referencedGroup != null ? referencedGroup : schema.Groups [RefName] as XmlSchemaGroup;

            if (g != null && g.Particle != null)
            {
                OptimizedParticle = g.Particle;
                OptimizedParticle = OptimizedParticle.GetOptimizedParticle(isTop);
                if (OptimizedParticle != XmlSchemaParticle.Empty && (ValidatedMinOccurs != 1 || ValidatedMaxOccurs != 1))
                {
                    OptimizedParticle = OptimizedParticle.GetShallowClone();
                    OptimizedParticle.OptimizedParticle = null;
                    OptimizedParticle.MinOccurs         = this.MinOccurs;
                    OptimizedParticle.MaxOccurs         = this.MaxOccurs;
                    OptimizedParticle.CompileOccurence(null, null);
                }
            }
            else
            {
                OptimizedParticle = XmlSchemaParticle.Empty;
            }
            busy = false;
            return(OptimizedParticle);
        }
コード例 #3
0
        internal override XmlSchemaParticle GetOptimizedParticle(bool isTop)
        {
            if (this.busy)
            {
                return(XmlSchemaParticle.Empty);
            }
            if (this.OptimizedParticle != null)
            {
                return(this.OptimizedParticle);
            }
            this.busy = true;
            XmlSchemaGroup xmlSchemaGroup = (this.referencedGroup == null) ? (this.schema.Groups[this.RefName] as XmlSchemaGroup) : this.referencedGroup;

            if (xmlSchemaGroup != null && xmlSchemaGroup.Particle != null)
            {
                this.OptimizedParticle = xmlSchemaGroup.Particle;
                this.OptimizedParticle = this.OptimizedParticle.GetOptimizedParticle(isTop);
                if (this.OptimizedParticle != XmlSchemaParticle.Empty && (base.ValidatedMinOccurs != 1m || base.ValidatedMaxOccurs != 1m))
                {
                    this.OptimizedParticle = this.OptimizedParticle.GetShallowClone();
                    this.OptimizedParticle.OptimizedParticle = null;
                    this.OptimizedParticle.MinOccurs         = base.MinOccurs;
                    this.OptimizedParticle.MaxOccurs         = base.MaxOccurs;
                    this.OptimizedParticle.CompileOccurence(null, null);
                }
            }
            else
            {
                this.OptimizedParticle = XmlSchemaParticle.Empty;
            }
            this.busy = false;
            return(this.OptimizedParticle);
        }
コード例 #4
0
        internal override int Validate(ValidationEventHandler h, XmlSchema schema)
        {
            if (IsValidated(schema.ValidationId))
            {
                return(errorCount);
            }

            referencedGroup = schema.Groups [RefName] as XmlSchemaGroup;
            // it might be missing sub components.
            if (referencedGroup == null)
            {
                if (!schema.IsNamespaceAbsent(RefName.Namespace))
                {
                    error(h, "Referenced group " + RefName + " was not found in the corresponding schema.");
                }
            }
            // See Errata E1-26: minOccurs=0 is now allowed.
            else if (referencedGroup.Particle is XmlSchemaAll && ValidatedMaxOccurs != 1)
            {
                error(h, "Group reference to -all- particle must have schema component {maxOccurs}=1.");
            }
            if (TargetGroup != null)
            {
                TargetGroup.Validate(h, schema);
            }

            ValidationId = schema.ValidationId;
            return(errorCount);
        }
コード例 #5
0
        internal XmlSchemaObject Clone(XmlSchema parentSchema)
        {
            XmlSchemaGroup newGroup = (XmlSchemaGroup)MemberwiseClone();

            if (XmlSchemaComplexType.HasParticleRef(_particle, parentSchema))
            {
                newGroup._particle = XmlSchemaComplexType.CloneParticle(_particle, parentSchema) as XmlSchemaGroupBase;
            }
            newGroup._canonicalParticle = XmlSchemaParticle.Empty;
            return(newGroup);
        }
コード例 #6
0
        internal override XmlSchemaObject Clone()
        {
            XmlSchemaGroup newGroup = (XmlSchemaGroup)MemberwiseClone();

            if (XmlSchemaComplexType.HasParticleRef(this.particle))
            {
                newGroup.particle = XmlSchemaComplexType.CloneParticle(this.particle) as XmlSchemaGroupBase;
            }
            newGroup.canonicalParticle = XmlSchemaParticle.Empty;
            return(newGroup);
        }
コード例 #7
0
        internal XmlSchemaObject Clone(XmlSchema parentSchema)
        {
            XmlSchemaGroup group = (XmlSchemaGroup)base.MemberwiseClone();

            if (XmlSchemaComplexType.HasParticleRef(this.particle, parentSchema))
            {
                group.particle = XmlSchemaComplexType.CloneParticle(this.particle, parentSchema) as XmlSchemaGroupBase;
            }
            group.canonicalParticle = XmlSchemaParticle.Empty;
            return(group);
        }
コード例 #8
0
		public override void FixtureInit()
		{
			XmlSchemaCompletionDataCollection schemas = new XmlSchemaCompletionDataCollection();
			schemas.Add(SchemaCompletionData);
			XmlSchemaCompletionData xsdSchemaCompletionData = new XmlSchemaCompletionData(ResourceManager.GetXsdSchema());
			schemas.Add(xsdSchemaCompletionData);
			XmlCompletionDataProvider provider = new XmlCompletionDataProvider(schemas, xsdSchemaCompletionData, String.Empty);
			
			string xml = GetSchema();			
			int index = xml.IndexOf("ref=\"block\"");
			index = xml.IndexOf("block", index);
			schemaGroup = (XmlSchemaGroup)XmlView.GetSchemaObjectSelected(xml, index, provider, SchemaCompletionData);
		}
コード例 #9
0
		public override void FixtureInit()
		{
			XmlSchemaCompletionCollection schemas = new XmlSchemaCompletionCollection();
			schemas.Add(SchemaCompletion);
			XmlSchemaCompletion xsdSchemaCompletion = new XmlSchemaCompletion(ResourceManager.ReadXsdSchema());
			schemas.Add(xsdSchemaCompletion);
			
			string xml = GetSchema();			
			int index = xml.IndexOf("ref=\"block\"");
			index = xml.IndexOf("block", index);
			XmlSchemaDefinition schemaDefinition = new XmlSchemaDefinition(schemas, SchemaCompletion);
			schemaGroup = (XmlSchemaGroup)schemaDefinition.GetSelectedSchemaObject(xml, index);
		}
コード例 #10
0
        internal XmlSchema DeepClone()
        {
            XmlSchema schema = new XmlSchema {
                attributeFormDefault = this.attributeFormDefault,
                elementFormDefault   = this.elementFormDefault,
                blockDefault         = this.blockDefault,
                finalDefault         = this.finalDefault,
                targetNs             = this.targetNs,
                version        = this.version,
                isPreprocessed = this.isPreprocessed
            };

            for (int i = 0; i < this.items.Count; i++)
            {
                XmlSchemaObject      obj2;
                XmlSchemaComplexType type = this.items[i] as XmlSchemaComplexType;
                if (type != null)
                {
                    obj2 = type.Clone(this);
                }
                else
                {
                    XmlSchemaElement element = this.items[i] as XmlSchemaElement;
                    if (element != null)
                    {
                        obj2 = element.Clone(this);
                    }
                    else
                    {
                        XmlSchemaGroup group = this.items[i] as XmlSchemaGroup;
                        if (group != null)
                        {
                            obj2 = group.Clone(this);
                        }
                        else
                        {
                            obj2 = this.items[i].Clone();
                        }
                    }
                }
                schema.Items.Add(obj2);
            }
            for (int j = 0; j < this.includes.Count; j++)
            {
                XmlSchemaExternal item = (XmlSchemaExternal)this.includes[j].Clone();
                schema.Includes.Add(item);
            }
            schema.Namespaces = base.Namespaces;
            schema.BaseUri    = this.BaseUri;
            return(schema);
        }
コード例 #11
0
        private bool IsValidGroupRedefine(XmlSchemaObject existingObject, XmlSchemaObject item)
        {
            XmlSchemaGroup group = item as XmlSchemaGroup;

            if (existingObject == group.Redefined)   //group is the redefinition of existingObject
            {
                XmlSchemaGroup existingGroup = existingObject as XmlSchemaGroup;
                if (existingGroup.CanonicalParticle == null)   //If the existing one is not already compiled, then replace.
                {
                    return(true);
                }
            }
            return(false);
        }
コード例 #12
0
        private bool IsValidGroupRedefine(XmlSchemaObject existingObject, XmlSchemaObject item, XmlSchemaObjectTable table)
        {
            XmlSchemaGroup group         = (item as XmlSchemaGroup) !;
            XmlSchemaGroup existingGroup = (existingObject as XmlSchemaGroup) !;

            if (existingGroup == group.Redefined)
            {                                                 //group is the redefinition of existingObject
                if (existingGroup.CanonicalParticle == null)
                {                                             //If the existing one is not already compiled, then replace.
                    table.Insert(group.QualifiedName, group); //Update with redefined entry
                    return(true);
                }
            }
            else if (existingGroup.Redefined == group)
            { //Redefined type already exists in the set, original type is added after redefined type, ignore the original type
                return(true);
            }
            return(false);
        }
コード例 #13
0
        private bool IsValidGroupRedefine(XmlSchemaObject existingObject, XmlSchemaObject item, XmlSchemaObjectTable table)
        {
            XmlSchemaGroup group  = item as XmlSchemaGroup;
            XmlSchemaGroup group2 = existingObject as XmlSchemaGroup;

            if (group2 == group.Redefined)
            {
                if (group2.CanonicalParticle == null)
                {
                    table.Insert(group.QualifiedName, group);
                    return(true);
                }
            }
            else if (group2.Redefined == group)
            {
                return(true);
            }
            return(false);
        }
コード例 #14
0
 void Write57_XmlSchemaGroup(XmlSchemaGroup o) {
     if ((object)o == null) return;
     WriteStartElement("group");
     
     WriteAttribute(@"id", @"", ((System.String)o.@Id));
     WriteAttribute(@"name", @"", ((System.String)o.@Name));
     WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o);
     Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation);
     if (o.@Particle is XmlSchemaSequence) {
         Write54_XmlSchemaSequence((XmlSchemaSequence)o.@Particle);
     }
     else if (o.@Particle is XmlSchemaChoice) {
         Write52_XmlSchemaChoice((XmlSchemaChoice)o.@Particle);
     }
     else if (o.@Particle is XmlSchemaAll) {
         Write43_XmlSchemaAll((XmlSchemaAll)o.@Particle);
     }
     WriteEndElement();
 }
コード例 #15
0
ファイル: XmlSchemaGroup.cs プロジェクト: pmq20/mono_forked
        //From the Errata
        //<group
        //  id = ID
        //  name = NCName
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (all | choice | sequence)?)
        //</group>
        internal static XmlSchemaGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaGroup group = new XmlSchemaGroup();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaGroup.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            group.LineNumber   = reader.LineNumber;
            group.LinePosition = reader.LinePosition;
            group.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    group.Id = reader.Value;
                }
                else if (reader.Name == "name")
                {
                    group.name = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for group", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, group);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(group);
            }

//			 Content: (annotation?, (all | choice | sequence)?)
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaGroup.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1 && reader.LocalName == "annotation")
                {
                    level = 2;                     //Only one annotation
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        group.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "all")
                    {
                        level = 3;
                        XmlSchemaAll all = XmlSchemaAll.Read(reader, h);
                        if (all != null)
                        {
                            group.Particle = all;
                        }
                        continue;
                    }
                    if (reader.LocalName == "choice")
                    {
                        level = 3;
                        XmlSchemaChoice choice = XmlSchemaChoice.Read(reader, h);
                        if (choice != null)
                        {
                            group.Particle = choice;
                        }
                        continue;
                    }
                    if (reader.LocalName == "sequence")
                    {
                        level = 3;
                        XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h);
                        if (sequence != null)
                        {
                            group.Particle = sequence;
                        }
                        continue;
                    }
                }
                reader.RaiseInvalidElementError();
            }
            return(group);
        }
コード例 #16
0
ファイル: XSD2Class.cs プロジェクト: nobled/mono
		private void GenerateGroupField (XmlSchemaGroup group)
		{
			GenerateParticleField (group.Particle);
		}
コード例 #17
0
 protected override void Visit(XmlSchemaGroup group)
 {
     _groups.Add(group);
 }
コード例 #18
0
 private void RecursivelyCheckRedefinedGroups(XmlSchemaGroup redefinedGroup, XmlSchemaGroup baseGroup) {
     if (baseGroup.Redefined != null) {
         RecursivelyCheckRedefinedGroups(baseGroup, baseGroup.Redefined);
     }
     if (redefinedGroup.SelfReferenceCount == 0) {
         if (baseGroup.CanonicalParticle == null) {
             baseGroup.CanonicalParticle = CannonicalizeParticle(baseGroup.Particle, true);
         }
         if (redefinedGroup.CanonicalParticle == null) {
             redefinedGroup.CanonicalParticle = CannonicalizeParticle(redefinedGroup.Particle, true);
         }
         CompileParticleElements(redefinedGroup.CanonicalParticle);
         CompileParticleElements(baseGroup.CanonicalParticle);
         CheckParticleDerivation(redefinedGroup.CanonicalParticle, baseGroup.CanonicalParticle);
     }
 }
コード例 #19
0
 private void CheckRefinedGroup(XmlSchemaGroup group) {
     int count = 0;
     if (group.Particle != null) {
         count = CountGroupSelfReference(group.Particle.Items, group.QualifiedName, group.Redefined);            
     }            
     if (count > 1) {
         SendValidationEvent(Res.Sch_MultipleGroupSelfRef, group);
     }
     group.SelfReferenceCount = count;
 }
コード例 #20
0
 private bool GatherGroupChoices(XmlSchemaGroup group, NameTable choiceElements, string identifier, string ns, ref bool needExplicitOrder, bool allowDuplicates)
 {
     return GatherGroupChoices(group.Particle, choiceElements, identifier, ns, ref needExplicitOrder, allowDuplicates);
 }
コード例 #21
0
ファイル: xmlschemaimporter.cs プロジェクト: ArildF/masters
 bool GatherGroupChoices(XmlSchemaGroup group, ArrayList list, string identifier, string ns) {
     return GatherGroupChoices(group.Particle, list, identifier, ns);
 }
コード例 #22
0
        private int CountGroupSelfReference(XmlSchemaObjectCollection items, XmlQualifiedName name, XmlSchemaGroup redefined) {
            int count = 0;
            foreach (XmlSchemaParticle particle in items) {
                if (particle is XmlSchemaGroupRef) {
                    XmlSchemaGroupRef groupRef = (XmlSchemaGroupRef)particle;
                    if (groupRef.RefName == name) {
                        groupRef.Redefined = redefined;
                        if (groupRef.MinOccurs != decimal.One || groupRef.MaxOccurs != decimal.One) {
                            SendValidationEvent(Res.Sch_MinMaxGroupRedefine, groupRef);
                        }
                        count ++;
                    }
                }
                else if (particle is XmlSchemaGroupBase) {
                    count += CountGroupSelfReference(((XmlSchemaGroupBase)particle).Items, name, redefined);
                }
                if (count > 1) {
                    break;
                }
            }
            return count;

        }
コード例 #23
0
        void DoCompile(ValidationEventHandler handler, Hashtable handledUris, XmlSchemaSet col, XmlResolver resolver)
        {
            SetParent();
            CompilationId = col.CompilationId;
            schemas       = col;
            if (!schemas.Contains(this))              // e.g. xs:import
            {
                schemas.Add(this);
            }

            attributeGroups.Clear();
            attributes.Clear();
            elements.Clear();
            groups.Clear();
            notations.Clear();
            schemaTypes.Clear();

            //1. Union and List are not allowed in block default
            if (BlockDefault != XmlSchemaDerivationMethod.All)
            {
                if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0)
                {
                    error(handler, "list is not allowed in blockDefault attribute");
                }
                if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0)
                {
                    error(handler, "union is not allowed in blockDefault attribute");
                }
            }

            //2. Substitution is not allowed in finaldefault.
            if (FinalDefault != XmlSchemaDerivationMethod.All)
            {
                if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0)
                {
                    error(handler, "substitution is not allowed in finalDefault attribute");
                }
            }

            //3. id must be of type ID
            XmlSchemaUtil.CompileID(Id, this, col.IDCollection, handler);

            //4. targetNamespace should be of type anyURI or absent
            if (TargetNamespace != null)
            {
                if (TargetNamespace.Length == 0)
                {
                    error(handler, "The targetNamespace attribute cannot have have empty string as its value.");
                }

                if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace))
                {
                    error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema");
                }
            }

            //5. version should be of type normalizedString
            if (!XmlSchemaUtil.CheckNormalizedString(Version))
            {
                error(handler, Version + "is not a valid value for version attribute of schema");
            }

            // Compile the content of this schema

            compilationItems = new XmlSchemaObjectCollection();
            for (int i = 0; i < Items.Count; i++)
            {
                compilationItems.Add(Items [i]);
            }

            // First, we run into inclusion schemas to collect
            // compilation target items into compiledItems.
            for (int i = 0; i < Includes.Count; i++)
            {
                XmlSchemaExternal ext = Includes [i] as XmlSchemaExternal;
                if (ext == null)
                {
                    error(handler, String.Format("Object of Type {0} is not valid in Includes Property of XmlSchema", Includes [i].GetType().Name));
                    continue;
                }

                if (ext.SchemaLocation == null)
                {
                    continue;
                }

                Stream stream = null;
                string url    = null;
                if (resolver != null)
                {
                    url = GetResolvedUri(resolver, ext.SchemaLocation);
                    if (handledUris.Contains(url))
                    {
                        // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur.
                        continue;
                    }
                    handledUris.Add(url, url);
                    try {
                        stream = resolver.GetEntity(new Uri(url), null, typeof(Stream)) as Stream;
                    } catch (Exception) {
                        // LAMESPEC: This is not good way to handle errors, but since we cannot know what kind of XmlResolver will come, so there are no mean to avoid this ugly catch.
                        warn(handler, "Could not resolve schema location URI: " + url);
                        stream = null;
                    }
                }

                // Process redefinition children in advance.
                XmlSchemaRedefine redefine = Includes [i] as XmlSchemaRedefine;
                if (redefine != null)
                {
                    for (int j = 0; j < redefine.Items.Count; j++)
                    {
                        XmlSchemaObject redefinedObj = redefine.Items [j];
                        redefinedObj.isRedefinedComponent = true;
                        redefinedObj.isRedefineChild      = true;
                        if (redefinedObj is XmlSchemaType ||
                            redefinedObj is XmlSchemaGroup ||
                            redefinedObj is XmlSchemaAttributeGroup)
                        {
                            compilationItems.Add(redefinedObj);
                        }
                        else
                        {
                            error(handler, "Redefinition is only allowed to simpleType, complexType, group and attributeGroup.");
                        }
                    }
                }

                XmlSchema includedSchema = null;
                if (stream == null)
                {
                    // It is missing schema components.
                    missedSubComponents = true;
                    continue;
                }
                else
                {
                    XmlTextReader xtr = null;
                    try {
                        xtr            = new XmlTextReader(url, stream, nameTable);
                        includedSchema = XmlSchema.Read(xtr, handler);
                    } finally {
                        if (xtr != null)
                        {
                            xtr.Close();
                        }
                    }
                    includedSchema.schemas = schemas;
                }
                includedSchema.SetParent();
                ext.Schema = includedSchema;

                // Set - actual - target namespace for the included schema * before compilation*.
                XmlSchemaImport import = ext as XmlSchemaImport;
                if (import != null)
                {
                    if (TargetNamespace == includedSchema.TargetNamespace)
                    {
                        error(handler, "Target namespace must be different from that of included schema.");
                        continue;
                    }
                    else if (includedSchema.TargetNamespace != import.Namespace)
                    {
                        error(handler, "Attribute namespace and its importing schema's target namespace must be the same.");
                        continue;
                    }
                }
                else
                {
                    if (TargetNamespace == null &&
                        includedSchema.TargetNamespace != null)
                    {
                        error(handler, "Target namespace is required to include a schema which has its own target namespace");
                        continue;
                    }
                    else if (TargetNamespace != null &&
                             includedSchema.TargetNamespace == null)
                    {
                        includedSchema.TargetNamespace = TargetNamespace;
                    }
                }

                // Do not compile included schema here.

                AddExternalComponentsTo(includedSchema, compilationItems);
            }

            // Compilation phase.
            // At least each Compile() must give unique (qualified) name for each component.
            // It also checks self-resolvable properties correctness.
            // Post compilation schema information contribution is not done here.
            // It should be done by Validate().
            for (int i = 0; i < compilationItems.Count; i++)
            {
                XmlSchemaObject obj = compilationItems [i];
                if (obj is XmlSchemaAnnotation)
                {
                    int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this);
                    errorCount += numerr;
                }
                else if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    int numerr = attr.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler);
                    }
                }
                else if (obj is XmlSchemaAttributeGroup)
                {
                    XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj;
                    int numerr = attrgrp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            AttributeGroups,
                            attrgrp,
                            attrgrp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj;
                    int numerr = ctype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            schemaTypes,
                            ctype,
                            ctype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj;
                    stype.islocal = false;                     //This simple type is toplevel
                    int numerr = stype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            SchemaTypes,
                            stype,
                            stype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaElement)
                {
                    XmlSchemaElement elem = (XmlSchemaElement)obj;
                    elem.parentIsSchema = true;
                    int numerr = elem.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Elements,
                            elem,
                            elem.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaGroup)
                {
                    XmlSchemaGroup grp    = (XmlSchemaGroup)obj;
                    int            numerr = grp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Groups,
                            grp,
                            grp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaNotation)
                {
                    XmlSchemaNotation ntn = (XmlSchemaNotation)obj;
                    int numerr            = ntn.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Notations,
                            ntn,
                            ntn.QualifiedName,
                            handler);
                    }
                }
                else
                {
                    ValidationHandler.RaiseValidationEvent(
                        handler,
                        null,
                        String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name),
                        null,
                        this,
                        null,
                        XmlSeverityType.Error);
                }
            }
        }
コード例 #24
0
 private void CleanupGroup(XmlSchemaGroup group)
 {
     this.CleanupParticle(group.Particle);
     group.CanonicalParticle = null;
     if (group.Redefined != null)
     {
         this.CleanupGroup(group.Redefined);
     }
 }
コード例 #25
0
ファイル: DCCodeGen.cs プロジェクト: awakegod/NETMF-LPC
 private void ProcessGroup(XmlSchemaGroup group, CodeTypeDeclaration codeType)
 {
         if (group.Particle.GetType() == typeof(XmlSchemaSequence))
         {
             ProcessSequence((XmlSchemaSequence)group.Particle, codeType);
         }
         else if (group.Particle.GetType() == typeof(XmlSchemaChoice))
         {
             ProcessChoice((XmlSchemaChoice)group.Particle, codeType);
         }
         else if (group.Particle.GetType() == typeof(XmlSchemaAll))
         {
             ProcessAll((XmlSchemaAll)group.Particle, codeType);
         }
         else
             throw new XmlSchemaException("Invalid particle type: " + group.Particle.ToString());
 }
コード例 #26
0
 protected override void Visit(XmlSchemaGroup group)
 {
     PushTopic(TopicType.Group, group.QualifiedName.Namespace, group, group.Name);
     base.Visit(group);
     PopTopic();
 }
コード例 #27
0
 private void CompileGroup(XmlSchemaGroup group) {
     if (group.IsProcessing) {
         SendValidationEvent(Res.Sch_GroupCircularRef, group);
         group.CanonicalParticle = XmlSchemaParticle.Empty;
     } 
     else {
         group.IsProcessing = true;
         if (group.CanonicalParticle == null) { 
             group.CanonicalParticle = CannonicalizeParticle(group.Particle, true, true); 
         }
         Debug.Assert(group.CanonicalParticle != null);
         group.IsProcessing = false;
     }
 }
 private static void CleanupGroup(XmlSchemaGroup group)
 {
     CleanupParticle(group.Particle);
     group.CanonicalParticle = null;
 }
コード例 #29
0
 private void CheckRefinedGroup(XmlSchemaGroup group)
 {
     int num = 0;
     if (group.Particle != null)
     {
         num = this.CountGroupSelfReference(group.Particle.Items, group.QualifiedName, group.Redefined);
     }
     if (num > 1)
     {
         base.SendValidationEvent("Sch_MultipleGroupSelfRef", group);
     }
     group.SelfReferenceCount = num;
 }
コード例 #30
0
ファイル: xsd.cs プロジェクト: ArildF/masters
        private static XmlSchema CreateFakeSoapEncodingSchema(string ns, string name) {

            // Create soap encoding schema 

            XmlSchema schema = new XmlSchema();
            schema.TargetNamespace = ns;

            // Add Array type:
            /*
              <xs:group name="Array">
                <xs:sequence>
                  <xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" processContents="lax" />
                </xs:sequence>
              </xs:group>
              <xs:element name="Array" type="tns:Array" />
              <xs:complexType name="Array">
                <xs:group minOccurs="0" ref="tns:Array" />
              </xs:complexType>
            */

            XmlSchemaGroup group = new XmlSchemaGroup();
            group.Name = "Array";
            XmlSchemaSequence seq = new XmlSchemaSequence();
            XmlSchemaAny any = new XmlSchemaAny();
            any.MinOccurs = 0;
            any.MaxOccurs = decimal.MaxValue;
            seq.Items.Add(any);
            any.Namespace = "##any";
            any.ProcessContents = XmlSchemaContentProcessing.Lax;

            group.Particle = seq;
            schema.Items.Add(group);

            XmlSchemaComplexType type = new XmlSchemaComplexType();
            type.Name = name;
            XmlSchemaGroupRef qroupRef = new XmlSchemaGroupRef();
            qroupRef.RefName = new XmlQualifiedName("Array", ns);
            type.Particle = qroupRef;
            XmlSchemaAttribute attribute = new XmlSchemaAttribute();
            attribute.RefName = new XmlQualifiedName("arrayType", ns);
            type.Attributes.Add(attribute);
            schema.Items.Add(type);

            attribute = new XmlSchemaAttribute();
            attribute.Use = XmlSchemaUse.None;
            attribute.Name = "arrayType";
            schema.Items.Add(attribute);

            AddSimpleType(schema, "base64", "base64Binary");

            // Add all types derived from the primitive XSD types

            AddElementAndType(schema, "anyURI", ns);
            AddElementAndType(schema, "base64Binary", ns);
            AddElementAndType(schema, "boolean", ns);
            AddElementAndType(schema, "byte", ns);
            AddElementAndType(schema, "date", ns);
            AddElementAndType(schema, "dateTime", ns);
            AddElementAndType(schema, "decimal", ns);
            AddElementAndType(schema, "double", ns);
            AddElementAndType(schema, "duration", ns);
            AddElementAndType(schema, "ENTITIES", ns);
            AddElementAndType(schema, "ENTITY", ns);
            AddElementAndType(schema, "float", ns);
            AddElementAndType(schema, "gDay", ns);
            AddElementAndType(schema, "gMonth", ns);
            AddElementAndType(schema, "gMonthDay", ns);
            AddElementAndType(schema, "gYear", ns);
            AddElementAndType(schema, "gYearMonth", ns);
            AddElementAndType(schema, "hexBinary", ns);
            AddElementAndType(schema, "ID", ns);
            AddElementAndType(schema, "IDREF", ns);
            AddElementAndType(schema, "IDREFS", ns);
            AddElementAndType(schema, "int", ns);
            AddElementAndType(schema, "integer", ns);
            AddElementAndType(schema, "language", ns);
            AddElementAndType(schema, "long", ns);
            AddElementAndType(schema, "Name", ns);
            AddElementAndType(schema, "NCName", ns);
            AddElementAndType(schema, "negativeInteger", ns);
            AddElementAndType(schema, "NMTOKEN", ns);
            AddElementAndType(schema, "NMTOKENS", ns);
            AddElementAndType(schema, "nonNegativeInteger", ns);
            AddElementAndType(schema, "nonPositiveInteger", ns);
            AddElementAndType(schema, "normalizedString", ns);
            AddElementAndType(schema, "positiveInteger", ns);
            AddElementAndType(schema, "QName", ns);
            AddElementAndType(schema, "short", ns);
            AddElementAndType(schema, "string", ns);
            AddElementAndType(schema, "time", ns);
            AddElementAndType(schema, "token", ns);
            AddElementAndType(schema, "unsignedByte", ns);
            AddElementAndType(schema, "unsignedInt", ns);
            AddElementAndType(schema, "unsignedLong", ns);
            AddElementAndType(schema, "unsignedShort", ns);

            return schema;
        }
コード例 #31
0
        private int CountGroupSelfReference(XmlSchemaObjectCollection items, XmlQualifiedName name, XmlSchemaGroup redefined) {
            int count = 0;
            for (int i = 0; i < items.Count; ++i) {
                XmlSchemaGroupRef groupRef = items[i] as XmlSchemaGroupRef;
                if (groupRef != null) {
                    if (groupRef.RefName == name) {
                        groupRef.Redefined = redefined;
                        if (groupRef.MinOccurs != decimal.One || groupRef.MaxOccurs != decimal.One) {
                            SendValidationEvent(Res.Sch_MinMaxGroupRedefine, groupRef);
                        }
                        count ++;
                    }
                }
                else if (items[i] is XmlSchemaGroupBase) {
                    count += CountGroupSelfReference(((XmlSchemaGroupBase)items[i]).Items, name, redefined);
                }
                if (count > 1) {
                    break;
                }
            }
            return count;

        }
コード例 #32
0
        internal static XmlSchemaGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaGroup xmlSchemaGroup = new XmlSchemaGroup();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "group")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaGroup.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaGroup.LineNumber   = reader.LineNumber;
            xmlSchemaGroup.LinePosition = reader.LinePosition;
            xmlSchemaGroup.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaGroup.Id = reader.Value;
                }
                else if (reader.Name == "name")
                {
                    xmlSchemaGroup.name = reader.Value;
                }
                else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
                {
                    XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for group", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaGroup);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaGroup);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "group")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaGroup.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaGroup.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    if (num <= 2)
                    {
                        if (reader.LocalName == "all")
                        {
                            num = 3;
                            XmlSchemaAll xmlSchemaAll = XmlSchemaAll.Read(reader, h);
                            if (xmlSchemaAll != null)
                            {
                                xmlSchemaGroup.Particle = xmlSchemaAll;
                            }
                            continue;
                        }
                        if (reader.LocalName == "choice")
                        {
                            num = 3;
                            XmlSchemaChoice xmlSchemaChoice = XmlSchemaChoice.Read(reader, h);
                            if (xmlSchemaChoice != null)
                            {
                                xmlSchemaGroup.Particle = xmlSchemaChoice;
                            }
                            continue;
                        }
                        if (reader.LocalName == "sequence")
                        {
                            num = 3;
                            XmlSchemaSequence xmlSchemaSequence = XmlSchemaSequence.Read(reader, h);
                            if (xmlSchemaSequence != null)
                            {
                                xmlSchemaGroup.Particle = xmlSchemaSequence;
                            }
                            continue;
                        }
                    }
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaGroup);
        }
コード例 #33
0
 private void CleanupGroup(XmlSchemaGroup group) {
     CleanupParticle(group.Particle);
     group.CanonicalParticle = null;
     //Clean up the original group if this is a redefined group
     if (group.Redefined != null) {
         CleanupGroup(group.Redefined);
     }
 }
コード例 #34
0
ファイル: XmlSchemaGroup.cs プロジェクト: user277/mono
		//From the Errata
		//<group 
		//  id = ID
		//  name = NCName
		//  {any attributes with non-schema namespace . . .}>
		//  Content: (annotation?, (all | choice | sequence)?)
		//</group>
		internal static XmlSchemaGroup Read(XmlSchemaReader reader, ValidationEventHandler h)
		{
			XmlSchemaGroup group = new XmlSchemaGroup();
			reader.MoveToElement();

			if(reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
			{
				error(h,"Should not happen :1: XmlSchemaGroup.Read, name="+reader.Name,null);
				reader.Skip();
				return null;
			}

			group.LineNumber = reader.LineNumber;
			group.LinePosition = reader.LinePosition;
			group.SourceUri = reader.BaseURI;

			while(reader.MoveToNextAttribute())
			{
				if(reader.Name == "id")
				{
					group.Id = reader.Value;
				}
				else if(reader.Name == "name")
				{
					group.name = reader.Value;
				}
				else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
				{
					error(h,reader.Name + " is not a valid attribute for group",null);
				}
				else
				{
					XmlSchemaUtil.ReadUnhandledAttribute(reader,group);
				}
			}
			
			reader.MoveToElement();
			if(reader.IsEmptyElement)
				return group;

//			 Content: (annotation?, (all | choice | sequence)?)
			int level = 1;
			while(reader.ReadNextElement())
			{
				if(reader.NodeType == XmlNodeType.EndElement)
				{
					if(reader.LocalName != xmlname)
						error(h,"Should not happen :2: XmlSchemaGroup.Read, name="+reader.Name,null);
					break;
				}
				if(level <= 1 && reader.LocalName == "annotation")
				{
					level = 2; //Only one annotation
					XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader,h);
					if(annotation != null)
						group.Annotation = annotation;
					continue;
				}
				if(level <= 2)
				{
					if(reader.LocalName == "all")
					{
						level = 3;
						XmlSchemaAll all = XmlSchemaAll.Read(reader,h);
						if(all != null)
							group.Particle = all;
						continue;
					}
					if(reader.LocalName == "choice")
					{
						level = 3;
						XmlSchemaChoice choice = XmlSchemaChoice.Read(reader,h);
						if(choice != null)
							group.Particle = choice;
						continue;
					}
					if(reader.LocalName == "sequence")
					{
						level = 3;
						XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
						if(sequence != null)
							group.Particle = sequence;
						continue;
					}
				}
				reader.RaiseInvalidElementError();
			}
			return group;
		}
コード例 #35
0
 private void CompileGroup(XmlSchemaGroup group) {
     if (group.IsProcessing) {
         SendValidationEvent(Res.Sch_GroupCircularRef, group);
         group.CanonicalParticle = XmlSchemaParticle.Empty;
     } 
     else {
         group.IsProcessing = true;
         if (group.CanonicalParticle == null) { 
             group.CanonicalParticle = CannonicalizeParticle(group.Particle, true); 
         }
         Debug.Assert(group.CanonicalParticle != null);
         group.IsProcessing = false; //Not enclosung in try -finally as cannonicalizeParticle will not throw exception
     }
 }
コード例 #36
0
ファイル: XsXsdGenerator.cs プロジェクト: xsharper/xsharper
        ///<summary>Generate XML schema for the given types
        ///</summary>
        ///<param name="ns">Default namespace</param>
        ///<param name="types">Types to include into schema</param>
        ///<param name="root">Root element</param>
        ///<param name="interfaces">Interface types</param>
        ///<returns>Built schema</returns>
        public static XmlSchema BuildSchema(string ns, Type[] types, Type root, Type[] interfaces)
        {
            XmlSchema xmlSchema = new XmlSchema();
            xmlSchema.Namespaces.Add("xsd", "http://www.w3.org/2001/XMLSchema");
            xmlSchema.Namespaces.Add("xsi", "http://www.w3.org/2001/XMLSchema-instance");
            xmlSchema.ElementFormDefault = XmlSchemaForm.Qualified;
            xmlSchema.AttributeFormDefault = XmlSchemaForm.Unqualified;
            xmlSchema.Namespaces.Add("ns", ns);
            xmlSchema.TargetNamespace = ns;

            // Comment
            XmlSchemaAnnotation annotation = new XmlSchemaAnnotation();
            XmlSchemaDocumentation documentation = new XmlSchemaDocumentation();
            XmlDocument helperDocument = new XmlDocument();
            string comment = String.Format("  XML schema for {0} , generated at {1}  ", ns, DateTime.Now.ToString());
            documentation.Markup = new XmlNode[1] { helperDocument.CreateComment(comment) };
            annotation.Items.Add(documentation);
            xmlSchema.Items.Add(annotation);

            // Create group "action" to refer to any action
            var ints = new Dictionary<Type, XmlSchemaGroup>();
            if (interfaces != null)
            {
                foreach (var intf in interfaces)
                {
                    var action = new XmlSchemaGroup();
                    action.Name = getXmlTypeName(intf);
                    action.Particle = new XmlSchemaChoice();
                    xmlSchema.Items.Add(action);
                    ints.Add(intf, action);
                }
            }

            Dictionary<Type, XmlSchemaType> xmlTypes = new Dictionary<Type, XmlSchemaType>();
            foreach (var type in types)
            {
                // If it does not have our XML header - skip it
                var na = (CustomAttributeHelper.First<XsTypeAttribute>(type));
                if (na == null)
                    continue;

                // Check if it is complex or simple
                XmlSchemaComplexType ct = new XmlSchemaComplexType();
                ct.Name = getXmlTypeName(type);

                XmlSchemaObjectCollection attr = createComplexType(type, ct, ns, ints);

                // Add the new element as an option to the "action" group
                foreach (var i in ints)
                {
                    bool isAction = (type.FindInterfaces((tp, nu) => tp == i.Key, null).Length != 0);
                    if (isAction)
                    {
                        foreach (var tp in CustomAttributeHelper.All<XsTypeAttribute>(type))
                        {
                            if (!string.IsNullOrEmpty(tp.Name))
                                i.Value.Particle.Items.Add(new XmlSchemaElement
                                {
                                    Name = tp.Name,
                                    MinOccurs = 0,
                                    SchemaTypeName = new XmlQualifiedName(ct.Name, ns)
                                });
                        }
                    }
                }

                // Work with attributes
                foreach (var o in generateAttributes(xmlSchema, type, xmlTypes, ns))
                    attr.Add(o);

                if (na.AnyAttribute)
                {
                    ct.AnyAttribute = new XmlSchemaAnyAttribute
                    {
                        ProcessContents = XmlSchemaContentProcessing.Skip
                    };
                }

                // Add type to the list
                xmlTypes.Add(type, ct);
                xmlSchema.Items.Add(ct);

                if (root.IsAssignableFrom(type))
                {
                    // Add all variations of Script names as element
                    foreach (var o in CustomAttributeHelper.All<XsTypeAttribute>(root))
                    {
                        xmlSchema.Items.Add(new XmlSchemaElement
                        {
                            Name = o.Name,
                            SchemaTypeName = new XmlQualifiedName(xmlTypes[typeof(Script)].Name, ns)
                        });
                    }
                }
            }
            return xmlSchema;
        }
コード例 #37
0
ファイル: XsdBuilder.cs プロジェクト: uQr/referencesource
 private void SetContainer(State state, object container) {
     switch (state) {
         case State.Root:
             break;
         case State.Schema:
             break;
         case State.Annotation:
             this.annotation = (XmlSchemaAnnotation)container;
             break;
         case State.Include:
             this.include = (XmlSchemaInclude)container;
             break;
         case State.Import:
             this.import = (XmlSchemaImport)container;
             break;
         case State.Element:
             this.element = (XmlSchemaElement)container;
             break;
         case State.Attribute:
             this.attribute = (XmlSchemaAttribute)container;
             break;
         case State.AttributeGroup:
             this.attributeGroup = (XmlSchemaAttributeGroup)container;
             break;
         case State.AttributeGroupRef:
             this.attributeGroupRef = (XmlSchemaAttributeGroupRef)container;
             break;
         case State.AnyAttribute:
             this.anyAttribute = (XmlSchemaAnyAttribute)container;
             break;
         case State.Group:
             this.group = (XmlSchemaGroup)container;
             break;
         case State.GroupRef:
             this.groupRef = (XmlSchemaGroupRef)container;
             break;
         case State.All:
             this.all = (XmlSchemaAll)container;
             break;
         case State.Choice:
             this.choice = (XmlSchemaChoice)container;
             break;
         case State.Sequence:
             this.sequence = (XmlSchemaSequence)container;
             break;
         case State.Any:
             this.anyElement = (XmlSchemaAny)container;
             break;
         case State.Notation:
             this.notation = (XmlSchemaNotation)container;
             break;
         case State.SimpleType:
             this.simpleType = (XmlSchemaSimpleType)container;
             break;
         case State.ComplexType:
             this.complexType = (XmlSchemaComplexType)container;
             break;
         case State.ComplexContent:
             this.complexContent = (XmlSchemaComplexContent)container;
             break;
         case State.ComplexContentExtension:
             this.complexContentExtension = (XmlSchemaComplexContentExtension)container;
             break;
         case State.ComplexContentRestriction:
             this.complexContentRestriction = (XmlSchemaComplexContentRestriction)container;
             break;
         case State.SimpleContent:
             this.simpleContent = (XmlSchemaSimpleContent)container;
             break;
         case State.SimpleContentExtension:
             this.simpleContentExtension = (XmlSchemaSimpleContentExtension)container;
             break;
         case State.SimpleContentRestriction:
             this.simpleContentRestriction = (XmlSchemaSimpleContentRestriction)container;
             break;
         case State.SimpleTypeUnion:
             this.simpleTypeUnion = (XmlSchemaSimpleTypeUnion)container;
             break;
         case State.SimpleTypeList:
             this.simpleTypeList = (XmlSchemaSimpleTypeList)container;
             break;
         case State.SimpleTypeRestriction:
             this.simpleTypeRestriction = (XmlSchemaSimpleTypeRestriction)container;
             break;
         case State.Unique:
         case State.Key:
         case State.KeyRef:
             this.identityConstraint = (XmlSchemaIdentityConstraint)container;
             break;
         case State.Selector:
         case State.Field:
             this.xpath = (XmlSchemaXPath)container;
             break;
         case State.MinExclusive:
         case State.MinInclusive:
         case State.MaxExclusive:
         case State.MaxInclusive:
         case State.TotalDigits:
         case State.FractionDigits:
         case State.Length:
         case State.MinLength:
         case State.MaxLength:
         case State.Enumeration:
         case State.Pattern:
         case State.WhiteSpace:
             this.facet = (XmlSchemaFacet)container;
             break;
         case State.AppInfo:
             this.appInfo = (XmlSchemaAppInfo)container;
             break;
         case State.Documentation:
             this.documentation = (XmlSchemaDocumentation)container;
             break;
         case State.Redefine:
             this.redefine = (XmlSchemaRedefine)container;
             break;
         default:
             Debug.Assert(false, "State is " + state);
             break;
     }
 }
コード例 #38
0
ファイル: ConformanceChecker.cs プロジェクト: nobled/mono
		public virtual void Check (ConformanceCheckContext ctx, XmlSchemaGroup value) {}
コード例 #39
0
        internal static XmlSchemaRedefine Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaRedefine xmlSchemaRedefine = new XmlSchemaRedefine();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "redefine")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaRedefine.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaRedefine.LineNumber   = reader.LineNumber;
            xmlSchemaRedefine.LinePosition = reader.LinePosition;
            xmlSchemaRedefine.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaRedefine.Id = reader.Value;
                }
                else if (reader.Name == "schemaLocation")
                {
                    xmlSchemaRedefine.SchemaLocation = reader.Value;
                }
                else if ((reader.NamespaceURI == string.Empty && reader.Name != "xmlns") || reader.NamespaceURI == "http://www.w3.org/2001/XMLSchema")
                {
                    XmlSchemaObject.error(h, reader.Name + " is not a valid attribute for redefine", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaRedefine);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaRedefine);
            }
            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "redefine")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaRedefine.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (reader.LocalName == "annotation")
                {
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaRedefine.items.Add(xmlSchemaAnnotation);
                    }
                }
                else if (reader.LocalName == "simpleType")
                {
                    XmlSchemaSimpleType xmlSchemaSimpleType = XmlSchemaSimpleType.Read(reader, h);
                    if (xmlSchemaSimpleType != null)
                    {
                        xmlSchemaRedefine.items.Add(xmlSchemaSimpleType);
                    }
                }
                else if (reader.LocalName == "complexType")
                {
                    XmlSchemaComplexType xmlSchemaComplexType = XmlSchemaComplexType.Read(reader, h);
                    if (xmlSchemaComplexType != null)
                    {
                        xmlSchemaRedefine.items.Add(xmlSchemaComplexType);
                    }
                }
                else if (reader.LocalName == "group")
                {
                    XmlSchemaGroup xmlSchemaGroup = XmlSchemaGroup.Read(reader, h);
                    if (xmlSchemaGroup != null)
                    {
                        xmlSchemaRedefine.items.Add(xmlSchemaGroup);
                    }
                }
                else if (reader.LocalName == "attributeGroup")
                {
                    XmlSchemaAttributeGroup xmlSchemaAttributeGroup = XmlSchemaAttributeGroup.Read(reader, h);
                    if (xmlSchemaAttributeGroup != null)
                    {
                        xmlSchemaRedefine.items.Add(xmlSchemaAttributeGroup);
                    }
                }
                else
                {
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaRedefine);
        }
コード例 #40
0
        void DoCompile(ValidationEventHandler handler, List <CompiledSchemaMemo> handledUris, XmlSchemaSet col, XmlResolver resolver)
        {
            SetParent();
            CompilationId = col.CompilationId;
            schemas       = col;
            if (!schemas.Contains(this))              // e.g. xs:import
            {
                schemas.Add(this);
            }

            attributeGroups.Clear();
            attributes.Clear();
            elements.Clear();
            groups.Clear();
            notations.Clear();
            schemaTypes.Clear();
            named_identities.Clear();
            ids.Clear();
            compilationItems.Clear();

            //1. Union and List are not allowed in block default
            if (BlockDefault != XmlSchemaDerivationMethod.All)
            {
                if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0)
                {
                    error(handler, "list is not allowed in blockDefault attribute");
                }
                if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0)
                {
                    error(handler, "union is not allowed in blockDefault attribute");
                }
            }

            //2. Substitution is not allowed in finaldefault.
            if (FinalDefault != XmlSchemaDerivationMethod.All)
            {
                if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0)
                {
                    error(handler, "substitution is not allowed in finalDefault attribute");
                }
            }

            //3. id must be of type ID
            XmlSchemaUtil.CompileID(Id, this, IDCollection, handler);

            //4. targetNamespace should be of type anyURI or absent
            if (TargetNamespace != null)
            {
                if (TargetNamespace.Length == 0)
                {
                    error(handler, "The targetNamespace attribute cannot have have empty string as its value.");
                }

                if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace))
                {
                    error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema");
                }
            }

            //5. version should be of type normalizedString
            if (!XmlSchemaUtil.CheckNormalizedString(Version))
            {
                error(handler, Version + "is not a valid value for version attribute of schema");
            }

            // Compile the content of this schema

            for (int i = 0; i < Items.Count; i++)
            {
                compilationItems.Add(Items [i]);
            }

            // First, we run into inclusion schemas to collect
            // compilation target items into compiledItems.
            for (int i = 0; i < Includes.Count; i++)
            {
                ProcessExternal(handler, handledUris, resolver, Includes [i] as XmlSchemaExternal, col);
            }

            // Compilation phase.
            // At least each Compile() must give unique (qualified) name for each component.
            // It also checks self-resolvable properties correctness.
            // Post compilation schema information contribution is not done here.
            // It should be done by Validate().
            for (int i = 0; i < compilationItems.Count; i++)
            {
                XmlSchemaObject obj = compilationItems [i];
                if (obj is XmlSchemaAnnotation)
                {
                    int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this);
                    errorCount += numerr;
                }
                else if (obj is XmlSchemaAttribute)
                {
                    XmlSchemaAttribute attr = (XmlSchemaAttribute)obj;
                    int numerr = attr.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler);
                    }
                }
                else if (obj is XmlSchemaAttributeGroup)
                {
                    XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj;
                    int numerr = attrgrp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            AttributeGroups,
                            attrgrp,
                            attrgrp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaComplexType)
                {
                    XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj;
                    int numerr = ctype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            schemaTypes,
                            ctype,
                            ctype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaSimpleType)
                {
                    XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj;
                    stype.islocal = false;                     //This simple type is toplevel
                    int numerr = stype.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            SchemaTypes,
                            stype,
                            stype.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaElement)
                {
                    XmlSchemaElement elem = (XmlSchemaElement)obj;
                    elem.parentIsSchema = true;
                    int numerr = elem.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Elements,
                            elem,
                            elem.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaGroup)
                {
                    XmlSchemaGroup grp    = (XmlSchemaGroup)obj;
                    int            numerr = grp.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Groups,
                            grp,
                            grp.QualifiedName,
                            handler);
                    }
                }
                else if (obj is XmlSchemaNotation)
                {
                    XmlSchemaNotation ntn = (XmlSchemaNotation)obj;
                    int numerr            = ntn.Compile(handler, this);
                    errorCount += numerr;
                    if (numerr == 0)
                    {
                        XmlSchemaUtil.AddToTable(
                            Notations,
                            ntn,
                            ntn.QualifiedName,
                            handler);
                    }
                }
                else
                {
                    ValidationHandler.RaiseValidationEvent(
                        handler,
                        null,
                        String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name),
                        null,
                        this,
                        null,
                        XmlSeverityType.Error);
                }
            }
        }
コード例 #41
0
		internal override int Validate(ValidationEventHandler h, XmlSchema schema)
		{
			if (IsValidated (schema.ValidationId))
				return errorCount;

			referencedGroup = schema.Groups [RefName] as XmlSchemaGroup;
			// it might be missing sub components.
			if (referencedGroup == null) {
				if (!schema.IsNamespaceAbsent (RefName.Namespace))
					error (h, "Referenced group " + RefName + " was not found in the corresponding schema.");
			}
			// See Errata E1-26: minOccurs=0 is now allowed.
			else if (referencedGroup.Particle is XmlSchemaAll && ValidatedMaxOccurs != 1)
				error (h, "Group reference to -all- particle must have schema component {maxOccurs}=1.");
			if (TargetGroup != null)
				TargetGroup.Validate (h, schema);

			ValidationId = schema.ValidationId;
			return errorCount;
		}
コード例 #42
0
        private static void ReadContent(XmlSchema schema, XmlSchemaReader reader, ValidationEventHandler h)
        {
            reader.MoveToElement();
            if (reader.LocalName != "schema" && reader.NamespaceURI != XmlSchema.Namespace && reader.NodeType != XmlNodeType.Element)
            {
                error(h, "UNREACHABLE CODE REACHED: Method: Schema.ReadContent, " + reader.LocalName + ", " + reader.NamespaceURI, null);
            }

            //(include | import | redefine | annotation)*,
            //((simpleType | complexType | group | attributeGroup | element | attribute | notation | annotation)*
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchema.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (level <= 1)
                {
                    if (reader.LocalName == "include")
                    {
                        XmlSchemaInclude include = XmlSchemaInclude.Read(reader, h);
                        if (include != null)
                        {
                            schema.includes.Add(include);
                        }
                        continue;
                    }
                    if (reader.LocalName == "import")
                    {
                        XmlSchemaImport import = XmlSchemaImport.Read(reader, h);
                        if (import != null)
                        {
                            schema.includes.Add(import);
                        }
                        continue;
                    }
                    if (reader.LocalName == "redefine")
                    {
                        XmlSchemaRedefine redefine = XmlSchemaRedefine.Read(reader, h);
                        if (redefine != null)
                        {
                            schema.includes.Add(redefine);
                        }
                        continue;
                    }
                    if (reader.LocalName == "annotation")
                    {
                        XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                        if (annotation != null)
                        {
                            schema.items.Add(annotation);
                        }
                        continue;
                    }
                }
                if (level <= 2)
                {
                    level = 2;
                    if (reader.LocalName == "simpleType")
                    {
                        XmlSchemaSimpleType stype = XmlSchemaSimpleType.Read(reader, h);
                        if (stype != null)
                        {
                            schema.items.Add(stype);
                        }
                        continue;
                    }
                    if (reader.LocalName == "complexType")
                    {
                        XmlSchemaComplexType ctype = XmlSchemaComplexType.Read(reader, h);
                        if (ctype != null)
                        {
                            schema.items.Add(ctype);
                        }
                        continue;
                    }
                    if (reader.LocalName == "group")
                    {
                        XmlSchemaGroup group = XmlSchemaGroup.Read(reader, h);
                        if (group != null)
                        {
                            schema.items.Add(group);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        XmlSchemaAttributeGroup attributeGroup = XmlSchemaAttributeGroup.Read(reader, h);
                        if (attributeGroup != null)
                        {
                            schema.items.Add(attributeGroup);
                        }
                        continue;
                    }
                    if (reader.LocalName == "element")
                    {
                        XmlSchemaElement element = XmlSchemaElement.Read(reader, h);
                        if (element != null)
                        {
                            schema.items.Add(element);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attribute")
                    {
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            schema.items.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "notation")
                    {
                        XmlSchemaNotation notation = XmlSchemaNotation.Read(reader, h);
                        if (notation != null)
                        {
                            schema.items.Add(notation);
                        }
                        continue;
                    }
                    if (reader.LocalName == "annotation")
                    {
                        XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                        if (annotation != null)
                        {
                            schema.items.Add(annotation);
                        }
                        continue;
                    }
                }
                reader.RaiseInvalidElementError();
            }
        }
 private void CompileGroup(XmlSchemaGroup group)
 {
     if (group.IsProcessing)
     {
         base.SendValidationEvent("Sch_GroupCircularRef", group);
         group.CanonicalParticle = XmlSchemaParticle.Empty;
     }
     else
     {
         group.IsProcessing = true;
         if (group.CanonicalParticle == null)
         {
             group.CanonicalParticle = this.CannonicalizeParticle(group.Particle, true, true);
         }
         group.IsProcessing = false;
     }
 }
コード例 #44
0
//<redefine
//  id = ID
//  schemaLocation = anyURI
//  {any attributes with non-schema namespace . . .}>
//  Content: (annotation | (simpleType | complexType | group | attributeGroup))*
//</redefine>
        internal static XmlSchemaRedefine Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaRedefine redefine = new XmlSchemaRedefine();

            reader.MoveToElement();

            if (reader.NamespaceURI != XmlSchema.Namespace || reader.LocalName != xmlname)
            {
                error(h, "Should not happen :1: XmlSchemaRedefine.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }

            redefine.LineNumber   = reader.LineNumber;
            redefine.LinePosition = reader.LinePosition;
            redefine.SourceUri    = reader.BaseURI;

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    redefine.Id = reader.Value;
                }
                else if (reader.Name == "schemaLocation")
                {
                    redefine.SchemaLocation = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for redefine", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, redefine);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(redefine);
            }

            //(annotation | (simpleType | complexType | group | attributeGroup))*
            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaRedefine.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (reader.LocalName == "annotation")
                {
                    XmlSchemaAnnotation annotation = XmlSchemaAnnotation.Read(reader, h);
                    if (annotation != null)
                    {
                        redefine.items.Add(annotation);
                    }
                    continue;
                }
                if (reader.LocalName == "simpleType")
                {
                    XmlSchemaSimpleType simpleType = XmlSchemaSimpleType.Read(reader, h);
                    if (simpleType != null)
                    {
                        redefine.items.Add(simpleType);
                    }
                    continue;
                }
                if (reader.LocalName == "complexType")
                {
                    XmlSchemaComplexType complexType = XmlSchemaComplexType.Read(reader, h);
                    if (complexType != null)
                    {
                        redefine.items.Add(complexType);
                    }
                    continue;
                }
                if (reader.LocalName == "group")
                {
                    XmlSchemaGroup group = XmlSchemaGroup.Read(reader, h);
                    if (group != null)
                    {
                        redefine.items.Add(group);
                    }
                    continue;
                }
                if (reader.LocalName == "attributeGroup")
                {
                    XmlSchemaAttributeGroup attributeGroup = XmlSchemaAttributeGroup.Read(reader, h);
                    if (attributeGroup != null)
                    {
                        redefine.items.Add(attributeGroup);
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(redefine);
        }
コード例 #45
0
 private void PreprocessGroup(XmlSchemaGroup group)
 {
     if (group.Name != null)
     {
         this.ValidateNameAttribute(group);
         group.SetQualifiedName(new XmlQualifiedName(group.Name, this.targetNamespace));
     }
     else
     {
         base.SendValidationEvent("Sch_MissRequiredAttribute", "name", group);
     }
     if (group.Particle == null)
     {
         base.SendValidationEvent("Sch_NoGroupParticle", group);
     }
     else
     {
         if (group.Particle.MinOccursString != null)
         {
             base.SendValidationEvent("Sch_ForbiddenAttribute", "minOccurs", group.Particle);
         }
         if (group.Particle.MaxOccursString != null)
         {
             base.SendValidationEvent("Sch_ForbiddenAttribute", "maxOccurs", group.Particle);
         }
         this.PreprocessParticle(group.Particle);
         this.PreprocessAnnotation(group);
         this.ValidateIdAttribute(group);
     }
 }
コード例 #46
0
        private void PreprocessGroup(XmlSchemaGroup group) {
            if (group.Name != null) { 
                ValidateNameAttribute(group);
                group.SetQualifiedName(new XmlQualifiedName(group.Name, this.targetNamespace));
            }
            else {
                SendValidationEvent(Res.Sch_MissRequiredAttribute, "name", group);
            }
            if (group.Particle == null) {
                SendValidationEvent(Res.Sch_NoGroupParticle, group);
                return;
            }
            if (group.Particle.MinOccursString != null) {
                SendValidationEvent(Res.Sch_ForbiddenAttribute, "minOccurs", group.Particle);
            }
            if (group.Particle.MaxOccursString != null) {
                SendValidationEvent(Res.Sch_ForbiddenAttribute, "maxOccurs", group.Particle);
            }

            PreprocessParticle(group.Particle);
            PreprocessAnnotation(group); //Set parent of annotation child of group
            ValidateIdAttribute(group);
        }
コード例 #47
0
 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;
 }
コード例 #48
0
ファイル: XsdVisitor.cs プロジェクト: willrawls/arp
 public virtual void VisitXmlSchemaGroup(XmlSchemaGroup group)
 {
     Dispatch(group.Particle);
 }