Inheritance: XmlSchemaGroupBase
Example #1
0
 public virtual void VisitXmlSchemaChoice(XmlSchemaChoice choice)
 {
     foreach (XmlSchemaObject o in choice.Items)
     {
         Dispatch(o);
     }
 }
Example #2
0
        private void ProcessLax(Choice c, string ns)
        {
            foreach (Particle p in c.Items)
            {
                Element el = p as Element;
                if (el == null)
                {
                    throw Error(c, String.Format("Target schema item contains unacceptable particle {0}. Only element is allowed here."));
                }
                if (ElementMatches(el, ns))
                {
                    InferElement(el, ns, false);
                    return;
                }
            }
            // append a new element particle to lax term.
            Element nel = new Element();

            if (source.NamespaceURI == ns)
            {
                nel.Name = source.LocalName;
            }
            else
            {
                nel.RefName = new QName(source.LocalName,
                                        source.NamespaceURI);
                AddImport(ns, source.NamespaceURI);
            }
            InferElement(nel, source.NamespaceURI, true);
            c.Items.Add(nel);
        }
Example #3
0
        internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle,
            ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            XmlSchemaAny any = baseParticle as XmlSchemaAny;
            if (any != null)
            {
            // NSRecurseCheckCardinality
            return ValidateNSRecurseCheckCardinality (any, h, schema, raiseError);
            }

            XmlSchemaChoice choice = baseParticle as XmlSchemaChoice;
            if (choice != null)
            {
            // RecurseLax
            if (!ValidateOccurenceRangeOK (choice, h, schema, raiseError))
                return false;

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

            if (raiseError)
            error (h, "Invalid choice derivation by restriction was found.");
            return false;
        }
Example #4
0
        /// <summary>
        /// Формируем XmlSchema для правильного отображения индикаторов группы в VGridControl
        /// </summary>
        /// <param name="elmList">названия всех по</param>
        /// <returns>Возвращаем поток в который записана XmlSchema</returns>
        public static MemoryStream CreateXmlSchemaForIndicatorsInGroup(List<string[]> elmList)
        {
            var xmlSchema = new XmlSchema();

            // <xs:element name="root">
            var elementRoot = new XmlSchemaElement();
            xmlSchema.Items.Add(elementRoot);
            elementRoot.Name = "root";
            // <xs:complexType>
            var complexType = new XmlSchemaComplexType();
            elementRoot.SchemaType = complexType;

            // <xs:choice minOccurs="0" maxOccurs="unbounded">
            var choice = new XmlSchemaChoice();
            complexType.Particle = choice;
            choice.MinOccurs = 0;
            choice.MaxOccursString = "unbounded";

            // <xs:element name="record">
            var elementRecord = new XmlSchemaElement();
            choice.Items.Add(elementRecord);
            elementRecord.Name = "record";
            // <xs:complexType>
            var complexType2 = new XmlSchemaComplexType();
            elementRecord.SchemaType = complexType2;

            // <xs:sequence>
            var sequence = new XmlSchemaSequence();
            complexType2.Particle = sequence;

            foreach (var el in elmList)
            {
                var element = new XmlSchemaElement();
                sequence.Items.Add(element);
                element.Name = el[0];
                element.SchemaTypeName = new XmlQualifiedName(el[1], "http://www.w3.org/2001/XMLSchema");
            }

            var schemaSet = new XmlSchemaSet();
            schemaSet.Add(xmlSchema);
            schemaSet.Compile();

            XmlSchema compiledSchema = null;

            foreach (XmlSchema schema1 in schemaSet.Schemas())
                compiledSchema = schema1;

            var nsmgr = new XmlNamespaceManager(new NameTable());
            nsmgr.AddNamespace("xs", "http://www.w3.org/2001/XMLSchema");

            var ms = new MemoryStream();
            if (compiledSchema != null) compiledSchema.Write(ms, nsmgr);
            ms.Position = 0;

            return ms;
        }
Example #5
0
        internal override XmlSchemaParticle GetOptimizedParticle(bool isTop)
        {
            if (OptimizedParticle != null)
            {
                return(OptimizedParticle);
            }

            if (Items.Count == 0 || ValidatedMaxOccurs == 0)
            {
                OptimizedParticle = XmlSchemaParticle.Empty;
            }
            // LAMESPEC: Regardless of isTop, it should remove pointless particle. It seems ContentTypeParticle design bug.
            else if (!isTop && Items.Count == 1 && ValidatedMinOccurs == 1 && ValidatedMaxOccurs == 1)
            {
                OptimizedParticle = ((XmlSchemaParticle)Items [0]).GetOptimizedParticle(false);
            }
            else
            {
                XmlSchemaChoice c = new XmlSchemaChoice();
                CopyInfo(c);
                for (int i = 0; i < Items.Count; i++)
                {
                    XmlSchemaParticle p = Items [i] as XmlSchemaParticle;
                    p = p.GetOptimizedParticle(false);
                    if (p == XmlSchemaParticle.Empty)
                    {
                        continue;
                    }
                    else if (p is XmlSchemaChoice && p.ValidatedMinOccurs == 1 && p.ValidatedMaxOccurs == 1)
                    {
                        XmlSchemaChoice pc = p as XmlSchemaChoice;
                        for (int ci = 0; ci < pc.Items.Count; ci++)
                        {
                            c.Items.Add(pc.Items [ci]);
                            c.CompiledItems.Add(pc.Items [ci]);
                        }
                    }
                    else
                    {
                        c.Items.Add(p);
                        c.CompiledItems.Add(p);
                    }
                }
                if (c.Items.Count == 0)
                {
                    OptimizedParticle = XmlSchemaParticle.Empty;
                }
                else
                {
                    OptimizedParticle = c;
                }
            }
            return(OptimizedParticle);
        }
 internal override XmlSchemaParticle GetOptimizedParticle(bool isTop)
 {
     if (this.OptimizedParticle != null)
     {
         return(this.OptimizedParticle);
     }
     if (this.Items.Count == 0 || base.ValidatedMaxOccurs == 0m)
     {
         this.OptimizedParticle = XmlSchemaParticle.Empty;
     }
     else if (!isTop && this.Items.Count == 1 && base.ValidatedMinOccurs == 1m && base.ValidatedMaxOccurs == 1m)
     {
         this.OptimizedParticle = ((XmlSchemaParticle)this.Items[0]).GetOptimizedParticle(false);
     }
     else
     {
         XmlSchemaChoice xmlSchemaChoice = new XmlSchemaChoice();
         this.CopyInfo(xmlSchemaChoice);
         for (int i = 0; i < this.Items.Count; i++)
         {
             XmlSchemaParticle xmlSchemaParticle = this.Items[i] as XmlSchemaParticle;
             xmlSchemaParticle = xmlSchemaParticle.GetOptimizedParticle(false);
             if (xmlSchemaParticle != XmlSchemaParticle.Empty)
             {
                 if (xmlSchemaParticle is XmlSchemaChoice && xmlSchemaParticle.ValidatedMinOccurs == 1m && xmlSchemaParticle.ValidatedMaxOccurs == 1m)
                 {
                     XmlSchemaChoice xmlSchemaChoice2 = xmlSchemaParticle as XmlSchemaChoice;
                     for (int j = 0; j < xmlSchemaChoice2.Items.Count; j++)
                     {
                         xmlSchemaChoice.Items.Add(xmlSchemaChoice2.Items[j]);
                         xmlSchemaChoice.CompiledItems.Add(xmlSchemaChoice2.Items[j]);
                     }
                 }
                 else
                 {
                     xmlSchemaChoice.Items.Add(xmlSchemaParticle);
                     xmlSchemaChoice.CompiledItems.Add(xmlSchemaParticle);
                 }
             }
         }
         if (xmlSchemaChoice.Items.Count == 0)
         {
             this.OptimizedParticle = XmlSchemaParticle.Empty;
         }
         else
         {
             this.OptimizedParticle = xmlSchemaChoice;
         }
     }
     return(this.OptimizedParticle);
 }
Example #7
0
        private void InferComplexContent(Element el, string ns,
                                         bool isNew)
        {
            ComplexType ct = ToComplexType(el);

            ToComplexContentType(ct);

            int  position = 0;
            bool consumed = false;

            do
            {
                switch (source.NodeType)
                {
                case XmlNodeType.Element:
                    Sequence s = PopulateSequence(ct);
                    Choice   c = s.Items.Count > 0 ?
                                 s.Items [0] as Choice :
                                 null;
                    if (c != null)
                    {
                        ProcessLax(c, ns);
                    }
                    else
                    {
                        ProcessSequence(ct, s, ns,
                                        ref position,
                                        ref consumed,
                                        isNew);
                    }
                    source.MoveToContent();
                    break;

                case XmlNodeType.Text:
                case XmlNodeType.CDATA:
                case XmlNodeType.SignificantWhitespace:
                    MarkAsMixed(ct);
                    source.ReadString();
                    source.MoveToContent();
                    break;

                case XmlNodeType.EndElement:
                    return;                     // finished

                case XmlNodeType.None:
                    throw new NotImplementedException("Internal Error: Should not happen.");
                }
            } while (true);
        }
Example #8
0
        // Note that it does not return the changed sequence.
        private Choice ToSequenceOfChoice(Sequence s)
        {
            Choice c = new Choice();

            if (laxOccurrence)
            {
                c.MinOccurs = 0;
            }
            c.MaxOccursString = "unbounded";
            foreach (Particle p in s.Items)
            {
                c.Items.Add(p);
            }
            s.Items.Clear();
            s.Items.Add(c);
            return(c);
        }
        protected internal override void Write(XmlSchemaObject obj)
        {
            var type = (XmlSchemaComplexType) obj;
            var choice = new XmlSchemaChoice {MinOccurs = 0};

            if (MaxOccurs != null)
            {
                choice.MaxOccurs = MaxOccurs.Value;
            }

            foreach (var choiceType in Types)
            {
                var element = new XmlSchemaElement();
                choiceType.Write(element);
                choice.Items.Add(element);
            }

            type.Particle = choice;
            base.Write(obj);
        }
        internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle, ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            XmlSchemaAny xmlSchemaAny = baseParticle as XmlSchemaAny;

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

            if (xmlSchemaChoice != null)
            {
                return(this.ValidateOccurenceRangeOK(xmlSchemaChoice, h, schema, raiseError) && ((xmlSchemaChoice.ValidatedMinOccurs == 0m && xmlSchemaChoice.ValidatedMaxOccurs == 0m && base.ValidatedMinOccurs == 0m && base.ValidatedMaxOccurs == 0m) || base.ValidateSeqRecurseMapSumCommon(xmlSchemaChoice, h, schema, true, false, raiseError)));
            }
            if (raiseError)
            {
                base.error(h, "Invalid choice derivation by restriction was found.");
            }
            return(false);
        }
Example #11
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 XmlSchemaParticle CannonicalizeChoice(XmlSchemaChoice choice, bool root, bool substitution)
 {
     XmlSchemaChoice source = choice;
     if (choice.Items.Count > 0)
     {
         XmlSchemaChoice choice3 = new XmlSchemaChoice {
             MinOccurs = choice.MinOccurs,
             MaxOccurs = choice.MaxOccurs
         };
         for (int i = 0; i < choice.Items.Count; i++)
         {
             XmlSchemaParticle item = this.CannonicalizeParticle((XmlSchemaParticle) choice.Items[i], false, substitution);
             if (item != XmlSchemaParticle.Empty)
             {
                 if (((item.MinOccurs == 1M) && (item.MaxOccurs == 1M)) && (item is XmlSchemaChoice))
                 {
                     XmlSchemaChoice choice4 = (XmlSchemaChoice) item;
                     for (int j = 0; j < choice4.Items.Count; j++)
                     {
                         choice3.Items.Add(choice4.Items[j]);
                     }
                 }
                 else
                 {
                     choice3.Items.Add(item);
                 }
             }
         }
         choice = choice3;
     }
     if (!root && (choice.Items.Count == 0))
     {
         if (choice.MinOccurs != 0M)
         {
             base.SendValidationEvent("Sch_EmptyChoice", source, XmlSeverityType.Warning);
         }
         return XmlSchemaParticle.Empty;
     }
     if ((!root && (choice.Items.Count == 1)) && ((choice.MinOccurs == 1M) && (choice.MaxOccurs == 1M)))
     {
         return (XmlSchemaParticle) choice.Items[0];
     }
     return choice;
 }
 void Write52_XmlSchemaChoice(XmlSchemaChoice o) {
     if ((object)o == null) return;
     System.Type t = o.GetType();
     WriteStartElement("choice");
     
     WriteAttribute(@"id", @"", ((System.String)o.@Id));
     WriteAttribute("minOccurs", "", XmlConvert.ToString(o.MinOccurs));
     WriteAttribute(@"maxOccurs", @"", o.MaxOccurs == decimal.MaxValue ? "unbounded" : XmlConvert.ToString(o.MaxOccurs));
     WriteAttributes((XmlAttribute[])o.@UnhandledAttributes, o);
     Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o.@Annotation);
     WriteSortedItems(o.@Items);
     WriteEndElement();
 }
Example #14
0
        //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);
        }
Example #15
0
		private void ProcessLax (Choice c, string ns)
		{
			foreach (Particle p in c.Items) {
				Element el = p as Element;
				if (el == null)
					throw Error (c, String.Format ("Target schema item contains unacceptable particle {0}. Only element is allowed here."));
				if (ElementMatches (el, ns)) {
					InferElement (el, ns, false);
					return;
				}
			}
			// append a new element particle to lax term.
			Element nel = new Element ();
			if (source.NamespaceURI == ns)
				nel.Name = source.LocalName;
			else {
				nel.RefName = new QName (source.LocalName,
					source.NamespaceURI);
				AddImport (ns, source.NamespaceURI);
			}
			InferElement (nel, source.NamespaceURI, true);
			c.Items.Add (nel);
		}
 private void ExportElementAccessors(XmlSchemaGroupBase group, ElementAccessor[] accessors, bool repeats, bool valueTypeOptional, string ns)
 {
     if (accessors.Length != 0)
     {
         if (accessors.Length == 1)
         {
             this.ExportElementAccessor(group, accessors[0], repeats, valueTypeOptional, ns);
         }
         else
         {
             XmlSchemaChoice choice = new XmlSchemaChoice {
                 MaxOccurs = repeats ? 79228162514264337593543950335M : 1M,
                 MinOccurs = repeats ? 0 : 1
             };
             for (int i = 0; i < accessors.Length; i++)
             {
                 this.ExportElementAccessor(choice, accessors[i], false, valueTypeOptional, ns);
             }
             if (choice.Items.Count > 0)
             {
                 group.Items.Add(choice);
             }
         }
     }
 }
Example #17
0
		//<choice
		//  id = ID
		//  maxOccurs =  (nonNegativeInteger | unbounded)  : 1
		//  minOccurs = nonNegativeInteger : 1
		//  {any attributes with non-schema namespace . . .}>
		//  Content: (annotation?, (element | group | choice | sequence | any)*)
		//</choice>
		internal static XmlSchemaChoice Read(XmlSchemaReader reader, ValidationEventHandler h)
		{
			XmlSchemaChoice choice = new XmlSchemaChoice();
			reader.MoveToElement();

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

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

			while(reader.MoveToNextAttribute())
			{
				if(reader.Name == "id")
				{
					choice.Id = reader.Value;
				}
				else if(reader.Name == "maxOccurs")
				{
					try
					{
						choice.MaxOccursString = reader.Value;
					}
					catch(Exception e)
					{
						error(h,reader.Value + " is an invalid value for maxOccurs",e);
					}
				}
				else if(reader.Name == "minOccurs")
				{
					try
					{
						choice.MinOccursString = reader.Value;
					}
					catch(Exception e)
					{
						error(h,reader.Value + " is an invalid value for minOccurs",e);
					}
				}
				else if((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
				{
					error(h,reader.Name + " is not a valid attribute for choice",null);
				}
				else
				{
					XmlSchemaUtil.ReadUnhandledAttribute(reader,choice);
				}
			}
			
			reader.MoveToElement();
			if(reader.IsEmptyElement)
				return choice;

			//  Content: (annotation?, (element | group | choice | sequence | any)*)
			int level = 1;
			while(reader.ReadNextElement())
			{
				if(reader.NodeType == XmlNodeType.EndElement)
				{
					if(reader.LocalName != xmlname)
						error(h,"Should not happen :2: XmlSchemaChoice.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)
						choice.Annotation = annotation;
					continue;
				}
				if(level <=2)
				{
					if(reader.LocalName == "element")
					{
						level = 2;
						XmlSchemaElement element = XmlSchemaElement.Read(reader,h);
						if(element != null)
							choice.items.Add(element);
						continue;
					}
					if(reader.LocalName == "group")
					{
						level = 2;
						XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader,h);
						if(group != null)
							choice.items.Add(group);
						continue;
					}
					if(reader.LocalName == "choice")
					{
						level = 2;
						XmlSchemaChoice ch = XmlSchemaChoice.Read(reader,h);
						if(ch != null)
							choice.items.Add(ch);
						continue;
					}
					if(reader.LocalName == "sequence")
					{
						level = 2;
						XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader,h);
						if(sequence != null)
							choice.items.Add(sequence);
						continue;
					}
					if(reader.LocalName == "any")
					{
						level = 2;
						XmlSchemaAny any = XmlSchemaAny.Read(reader,h);
						if(any != null)
							choice.items.Add(any);
						continue;
					}
				}
				reader.RaiseInvalidElementError();
			}
			return choice;
		}
Example #18
0
		internal override XmlSchemaParticle GetOptimizedParticle (bool isTop)
		{
			if (OptimizedParticle != null)
				return OptimizedParticle;

			if (Items.Count == 0 || ValidatedMaxOccurs == 0)
				OptimizedParticle = XmlSchemaParticle.Empty;
			// LAMESPEC: Regardless of isTop, it should remove pointless particle. It seems ContentTypeParticle design bug.
			else if (!isTop && Items.Count == 1 && ValidatedMinOccurs == 1 && ValidatedMaxOccurs == 1)
				OptimizedParticle = ((XmlSchemaParticle) Items [0]).GetOptimizedParticle (false);
			else {
				XmlSchemaChoice c = new XmlSchemaChoice ();
				CopyInfo (c);
				for (int i = 0; i < Items.Count; i++) {
					XmlSchemaParticle p = Items [i] as XmlSchemaParticle;
					p = p.GetOptimizedParticle (false);
					if (p == XmlSchemaParticle.Empty)
						continue;
					else if (p is XmlSchemaChoice && p.ValidatedMinOccurs == 1 && p.ValidatedMaxOccurs == 1) {
						XmlSchemaChoice pc = p as XmlSchemaChoice;
						for (int ci = 0; ci < pc.Items.Count; ci++) {
							c.Items.Add (pc.Items [ci]);
							c.CompiledItems.Add (pc.Items [ci]);
						}
					}
					else {
						c.Items.Add (p);
						c.CompiledItems.Add (p);
					}
				}
				if (c.Items.Count == 0)
					OptimizedParticle = XmlSchemaParticle.Empty;
				else
					OptimizedParticle = c;
			}
			return OptimizedParticle;
		}
Example #19
0
            protected XmlSchemaComplexType CreateTaskListComplexType(Type[] tasks, Type[] dataTypes, bool includeProjectLevelItems)
            {
                XmlSchemaComplexType tasklistCT = new XmlSchemaComplexType();
                XmlSchemaChoice choice = new XmlSchemaChoice();
                choice.MinOccurs = 0;
                choice.MaxOccursString = "unbounded";

                tasklistCT.Particle = choice;

                foreach (Type t in tasks) {
                    XmlSchemaElement taskElement = new XmlSchemaElement();
                    string typeId = GenerateIDFromType(t);
                    XmlSchemaComplexType taskCT = FindComplexTypeByID(typeId);

                    taskElement.Name = GetTaskName(t);
                    taskElement.SchemaTypeName = taskCT.QualifiedName;

                    choice.Items.Add(taskElement);
                }

                foreach (Type t in dataTypes) {
                    XmlSchemaElement dataTypeElement = new XmlSchemaElement();
                    string typeId = GenerateIDFromType(t);
                    XmlSchemaComplexType dataTypeCT = FindComplexTypeByID(typeId);

                    dataTypeElement.Name = GetDataTypeName(t);
                    dataTypeElement.SchemaTypeName = dataTypeCT.QualifiedName;

                    choice.Items.Add(dataTypeElement);
                }

                if (includeProjectLevelItems) {
                    XmlSchemaElement targetElement = new XmlSchemaElement();

                    targetElement.Name = "target";
                    targetElement.SchemaTypeName = _targetCT.QualifiedName;

                    choice.Items.Add(targetElement);
                }

                return tasklistCT;
Example #20
0
        //<choice
        //  id = ID
        //  maxOccurs =  (nonNegativeInteger | unbounded)  : 1
        //  minOccurs = nonNegativeInteger : 1
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, (element | group | choice | sequence | any)*)
        //</choice>
        internal static XmlSchemaChoice Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaChoice choice = new XmlSchemaChoice();

            reader.MoveToElement();

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

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

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    choice.Id = reader.Value;
                }
                else if (reader.Name == "maxOccurs")
                {
                    try
                    {
                        choice.MaxOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for maxOccurs", e);
                    }
                }
                else if (reader.Name == "minOccurs")
                {
                    try
                    {
                        choice.MinOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for minOccurs", e);
                    }
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for choice", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, choice);
                }
            }

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

            //  Content: (annotation?, (element | group | choice | sequence | any)*)
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaChoice.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)
                    {
                        choice.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "element")
                    {
                        level = 2;
                        XmlSchemaElement element = XmlSchemaElement.Read(reader, h);
                        if (element != null)
                        {
                            choice.items.Add(element);
                        }
                        continue;
                    }
                    if (reader.LocalName == "group")
                    {
                        level = 2;
                        XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader, h);
                        if (group != null)
                        {
                            choice.items.Add(group);
                        }
                        continue;
                    }
                    if (reader.LocalName == "choice")
                    {
                        level = 2;
                        XmlSchemaChoice ch = XmlSchemaChoice.Read(reader, h);
                        if (ch != null)
                        {
                            choice.items.Add(ch);
                        }
                        continue;
                    }
                    if (reader.LocalName == "sequence")
                    {
                        level = 2;
                        XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h);
                        if (sequence != null)
                        {
                            choice.items.Add(sequence);
                        }
                        continue;
                    }
                    if (reader.LocalName == "any")
                    {
                        level = 2;
                        XmlSchemaAny any = XmlSchemaAny.Read(reader, h);
                        if (any != null)
                        {
                            choice.items.Add(any);
                        }
                        continue;
                    }
                }
                reader.RaiseInvalidElementError();
            }
            return(choice);
        }
        internal static XmlSchemaChoice Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaChoice xmlSchemaChoice = new XmlSchemaChoice();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "choice")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaChoice.Read, name=" + reader.Name, null);
                reader.SkipToEnd();
                return(null);
            }
            xmlSchemaChoice.LineNumber   = reader.LineNumber;
            xmlSchemaChoice.LinePosition = reader.LinePosition;
            xmlSchemaChoice.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    xmlSchemaChoice.Id = reader.Value;
                }
                else if (reader.Name == "maxOccurs")
                {
                    try
                    {
                        xmlSchemaChoice.MaxOccursString = reader.Value;
                    }
                    catch (Exception innerException)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is an invalid value for maxOccurs", innerException);
                    }
                }
                else if (reader.Name == "minOccurs")
                {
                    try
                    {
                        xmlSchemaChoice.MinOccursString = reader.Value;
                    }
                    catch (Exception innerException2)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is an invalid value for minOccurs", innerException2);
                    }
                }
                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 choice", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaChoice);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaChoice);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "choice")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaChoice.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaChoice.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    if (num <= 2)
                    {
                        if (reader.LocalName == "element")
                        {
                            num = 2;
                            XmlSchemaElement xmlSchemaElement = XmlSchemaElement.Read(reader, h);
                            if (xmlSchemaElement != null)
                            {
                                xmlSchemaChoice.items.Add(xmlSchemaElement);
                            }
                            continue;
                        }
                        if (reader.LocalName == "group")
                        {
                            num = 2;
                            XmlSchemaGroupRef xmlSchemaGroupRef = XmlSchemaGroupRef.Read(reader, h);
                            if (xmlSchemaGroupRef != null)
                            {
                                xmlSchemaChoice.items.Add(xmlSchemaGroupRef);
                            }
                            continue;
                        }
                        if (reader.LocalName == "choice")
                        {
                            num = 2;
                            XmlSchemaChoice xmlSchemaChoice2 = XmlSchemaChoice.Read(reader, h);
                            if (xmlSchemaChoice2 != null)
                            {
                                xmlSchemaChoice.items.Add(xmlSchemaChoice2);
                            }
                            continue;
                        }
                        if (reader.LocalName == "sequence")
                        {
                            num = 2;
                            XmlSchemaSequence xmlSchemaSequence = XmlSchemaSequence.Read(reader, h);
                            if (xmlSchemaSequence != null)
                            {
                                xmlSchemaChoice.items.Add(xmlSchemaSequence);
                            }
                            continue;
                        }
                        if (reader.LocalName == "any")
                        {
                            num = 2;
                            XmlSchemaAny xmlSchemaAny = XmlSchemaAny.Read(reader, h);
                            if (xmlSchemaAny != null)
                            {
                                xmlSchemaChoice.items.Add(xmlSchemaAny);
                            }
                            continue;
                        }
                    }
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaChoice);
        }
Example #22
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);
        }
 private bool IsElementFromGroupBase(XmlSchemaElement derivedElement, XmlSchemaGroupBase baseGroupBase) {
     if (baseGroupBase is XmlSchemaSequence) {
         XmlSchemaSequence virtualSeq = new XmlSchemaSequence();
         virtualSeq.MinOccurs = 1;
         virtualSeq.MaxOccurs = 1;
         virtualSeq.Items.Add(derivedElement);
         if (IsGroupBaseFromGroupBase((XmlSchemaGroupBase)virtualSeq, baseGroupBase, true)) {
             return true;
         }
         restrictionErrorMsg = Res.GetString(Res.Sch_ElementFromGroupBase1, derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo));
     }
     else if (baseGroupBase is XmlSchemaChoice) {
         XmlSchemaChoice virtualChoice = new XmlSchemaChoice();
         virtualChoice.MinOccurs = 1;
         virtualChoice.MaxOccurs = 1;
         virtualChoice.Items.Add(derivedElement);
         if (IsGroupBaseFromGroupBase((XmlSchemaGroupBase)virtualChoice, baseGroupBase, false)) {
             return true;
         }
         restrictionErrorMsg = Res.GetString(Res.Sch_ElementFromGroupBase2, derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo));
     }
     else if (baseGroupBase is XmlSchemaAll) {
         XmlSchemaAll virtualAll = new XmlSchemaAll();
         virtualAll.MinOccurs = 1;
         virtualAll.MaxOccurs = 1;
         virtualAll.Items.Add(derivedElement);
         if (IsGroupBaseFromGroupBase((XmlSchemaGroupBase)virtualAll, baseGroupBase, true)) {
             return true;
         }
         restrictionErrorMsg = Res.GetString(Res.Sch_ElementFromGroupBase3, derivedElement.QualifiedName.ToString(), derivedElement.LineNumber.ToString(NumberFormatInfo.InvariantInfo), derivedElement.LinePosition.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LineNumber.ToString(NumberFormatInfo.InvariantInfo), baseGroupBase.LinePosition.ToString(NumberFormatInfo.InvariantInfo));
     }
     return false;
 }
Example #24
0
 void WriteChoiceContent(XmlTextWriter xtw, string ns, XmlSchemaChoice choice, bool multiValue)
 {
     foreach (XmlSchemaObject item in choice.Items)
         WriteContentItem(xtw, ns, item, multiValue);
 }
 private bool IsSequenceFromChoice(XmlSchemaSequence derivedSequence, XmlSchemaChoice baseChoice) {
     decimal minOccurs, maxOccurs;
     minOccurs = derivedSequence.MinOccurs * derivedSequence.Items.Count;
     if (derivedSequence.MaxOccurs == decimal.MaxValue) {
         maxOccurs = decimal.MaxValue;
     }
     else {
         maxOccurs = derivedSequence.MaxOccurs * derivedSequence.Items.Count;
     }
     if (!IsValidOccurrenceRangeRestriction(minOccurs, maxOccurs, baseChoice.MinOccurs, baseChoice.MaxOccurs) || derivedSequence.Items.Count > baseChoice.Items.Count) {
         return false;
     }
     for (int i = 0; i < derivedSequence.Items.Count; ++i) {
         if (GetMappingParticle((XmlSchemaParticle)derivedSequence.Items[i], baseChoice.Items) < 0)
             return false;
     }
     return true;
 }
Example #26
0
		// Note that it does not return the changed sequence.
		private Choice ToSequenceOfChoice (Sequence s)
		{
			Choice c = new Choice ();
			if (laxOccurrence)
				c.MinOccurs = 0;
			c.MaxOccursString = "unbounded";
			foreach (Particle p in s.Items)
				c.Items.Add (p);
			s.Items.Clear ();
			s.Items.Add (c);
			return c;
		}
Example #27
0
 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;
     }
 }
Example #28
0
		XmlSchemaParticle GetSchemaArrayElement (XmlSchema currentSchema, XmlTypeMapElementInfoList infos)
		{
			int numInfos = infos.Count;
			if (numInfos > 0 && ((XmlTypeMapElementInfo)infos[0]).IsTextElement) numInfos--;
			if (numInfos == 0) return null;

			if (numInfos == 1)
			{
				XmlSchemaParticle selem = GetSchemaElement (currentSchema, (XmlTypeMapElementInfo) infos[infos.Count-1], true);
				selem.MinOccursString = "0";
				selem.MaxOccursString = "unbounded";
				return selem;
			}
			else
			{
				XmlSchemaChoice schoice = new XmlSchemaChoice ();
				schoice.MinOccursString = "0";
				schoice.MaxOccursString = "unbounded";
				foreach (XmlTypeMapElementInfo einfo in infos)
				{
					if (einfo.IsTextElement) continue;
					schoice.Items.Add (GetSchemaElement (currentSchema, einfo, true));
				}
				return schoice;
			}
		}
Example #29
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);
        }
        internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaComplexContentExtension xmlSchemaComplexContentExtension = new XmlSchemaComplexContentExtension();

            reader.MoveToElement();
            if (reader.NamespaceURI != "http://www.w3.org/2001/XMLSchema" || reader.LocalName != "extension")
            {
                XmlSchemaObject.error(h, "Should not happen :1: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null);
                reader.Skip();
                return(null);
            }
            xmlSchemaComplexContentExtension.LineNumber   = reader.LineNumber;
            xmlSchemaComplexContentExtension.LinePosition = reader.LinePosition;
            xmlSchemaComplexContentExtension.SourceUri    = reader.BaseURI;
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception ex;
                    xmlSchemaComplexContentExtension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out ex);
                    if (ex != null)
                    {
                        XmlSchemaObject.error(h, reader.Value + " is not a valid value for base attribute", ex);
                    }
                }
                else if (reader.Name == "id")
                {
                    xmlSchemaComplexContentExtension.Id = 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 extension", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, xmlSchemaComplexContentExtension);
                }
            }
            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(xmlSchemaComplexContentExtension);
            }
            int num = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "extension")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaComplexContentExtension.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaComplexContentExtension.Annotation = xmlSchemaAnnotation;
                    }
                }
                else
                {
                    if (num <= 2)
                    {
                        if (reader.LocalName == "group")
                        {
                            num = 3;
                            XmlSchemaGroupRef xmlSchemaGroupRef = XmlSchemaGroupRef.Read(reader, h);
                            if (xmlSchemaGroupRef != null)
                            {
                                xmlSchemaComplexContentExtension.particle = xmlSchemaGroupRef;
                            }
                            continue;
                        }
                        if (reader.LocalName == "all")
                        {
                            num = 3;
                            XmlSchemaAll xmlSchemaAll = XmlSchemaAll.Read(reader, h);
                            if (xmlSchemaAll != null)
                            {
                                xmlSchemaComplexContentExtension.particle = xmlSchemaAll;
                            }
                            continue;
                        }
                        if (reader.LocalName == "choice")
                        {
                            num = 3;
                            XmlSchemaChoice xmlSchemaChoice = XmlSchemaChoice.Read(reader, h);
                            if (xmlSchemaChoice != null)
                            {
                                xmlSchemaComplexContentExtension.particle = xmlSchemaChoice;
                            }
                            continue;
                        }
                        if (reader.LocalName == "sequence")
                        {
                            num = 3;
                            XmlSchemaSequence xmlSchemaSequence = XmlSchemaSequence.Read(reader, h);
                            if (xmlSchemaSequence != null)
                            {
                                xmlSchemaComplexContentExtension.particle = xmlSchemaSequence;
                            }
                            continue;
                        }
                    }
                    if (num <= 3)
                    {
                        if (reader.LocalName == "attribute")
                        {
                            num = 3;
                            XmlSchemaAttribute xmlSchemaAttribute = XmlSchemaAttribute.Read(reader, h);
                            if (xmlSchemaAttribute != null)
                            {
                                xmlSchemaComplexContentExtension.Attributes.Add(xmlSchemaAttribute);
                            }
                            continue;
                        }
                        if (reader.LocalName == "attributeGroup")
                        {
                            num = 3;
                            XmlSchemaAttributeGroupRef xmlSchemaAttributeGroupRef = XmlSchemaAttributeGroupRef.Read(reader, h);
                            if (xmlSchemaAttributeGroupRef != null)
                            {
                                xmlSchemaComplexContentExtension.attributes.Add(xmlSchemaAttributeGroupRef);
                            }
                            continue;
                        }
                    }
                    if (num <= 4 && reader.LocalName == "anyAttribute")
                    {
                        num = 5;
                        XmlSchemaAnyAttribute xmlSchemaAnyAttribute = XmlSchemaAnyAttribute.Read(reader, h);
                        if (xmlSchemaAnyAttribute != null)
                        {
                            xmlSchemaComplexContentExtension.AnyAttribute = xmlSchemaAnyAttribute;
                        }
                    }
                    else
                    {
                        reader.RaiseInvalidElementError();
                    }
                }
            }
            return(xmlSchemaComplexContentExtension);
        }
Example #31
0
		/// <summary>
		/// Creates the schema type representing the graph type
		/// </summary>
		/// <returns>Type definition for a graph</returns>
		static XmlSchemaType CreateGraphType()
		{
			XmlSchemaChoice GraphChoice = new XmlSchemaChoice();
			GraphChoice.MinOccurs = 0;
			GraphChoice.MaxOccursString = "unbounded";
			GraphChoice.Items.Add(CreateSchemaElement("Include", ScriptSchemaStandardType.Include));
			GraphChoice.Items.Add(CreateSchemaElement("Option", ScriptSchemaStandardType.Option));
			GraphChoice.Items.Add(CreateSchemaElement("EnvVar", ScriptSchemaStandardType.EnvVar));
			GraphChoice.Items.Add(CreateSchemaElement("Property", ScriptSchemaStandardType.Property));
			GraphChoice.Items.Add(CreateSchemaElement("Agent", ScriptSchemaStandardType.Agent));
			GraphChoice.Items.Add(CreateSchemaElement("Trigger", ScriptSchemaStandardType.Trigger));
			GraphChoice.Items.Add(CreateSchemaElement("Aggregate", ScriptSchemaStandardType.Aggregate));
			GraphChoice.Items.Add(CreateSchemaElement("Report", ScriptSchemaStandardType.Report));
			GraphChoice.Items.Add(CreateSchemaElement("Badge", ScriptSchemaStandardType.Badge));
			GraphChoice.Items.Add(CreateSchemaElement("Notify", ScriptSchemaStandardType.Notify));
			GraphChoice.Items.Add(CreateSchemaElement("Warning", ScriptSchemaStandardType.Warning));
			GraphChoice.Items.Add(CreateSchemaElement("Error", ScriptSchemaStandardType.Error));
			GraphChoice.Items.Add(CreateDoElement(ScriptSchemaStandardType.Graph));
			GraphChoice.Items.Add(CreateSwitchElement(ScriptSchemaStandardType.Graph));
			GraphChoice.Items.Add(CreateForEachElement(ScriptSchemaStandardType.Graph));
			XmlSchemaComplexType GraphType = new XmlSchemaComplexType();
			GraphType.Name = GetTypeName(ScriptSchemaStandardType.Graph);
			GraphType.Particle = GraphChoice;
			return GraphType;
		}
 private XmlSchemaParticle CannonicalizeChoice(XmlSchemaChoice choice, bool root) {
     XmlSchemaChoice oldChoice = choice;
     if (choice.Items.Count > 0) {
         XmlSchemaChoice newChoice = new XmlSchemaChoice();
         newChoice.MinOccurs = choice.MinOccurs;
         newChoice.MaxOccurs = choice.MaxOccurs;
         CopyPosition(newChoice, choice, true);
         for (int i = 0; i < choice.Items.Count; ++i) {
             XmlSchemaParticle p1 = CannonicalizeParticle((XmlSchemaParticle)choice.Items[i], false);
             if (p1 != XmlSchemaParticle.Empty) {
                 if (p1.MinOccurs == decimal.One && p1.MaxOccurs == decimal.One && p1 is XmlSchemaChoice) {
                     XmlSchemaChoice p1Choice = p1 as XmlSchemaChoice;
                     for (int j = 0; j < p1Choice.Items.Count; ++j) {
                         newChoice.Items.Add(p1Choice.Items[j]);
                     }
                 }
                 else {
                     newChoice.Items.Add(p1);
                 }
             }
         }
         choice = newChoice;
     }
     if (!root && choice.Items.Count == 0) {
         if (choice.MinOccurs != decimal.Zero) {
             SendValidationEvent(Res.Sch_EmptyChoice, oldChoice, XmlSeverityType.Warning);
         }
         return XmlSchemaParticle.Empty;
     }
     else if (!root && choice.Items.Count == 1 && choice.MinOccurs == decimal.One && choice.MaxOccurs == decimal.One) {
         return (XmlSchemaParticle)choice.Items[0];
     }
     else {
         return choice;
     }
 }
Example #33
0
		/// <summary>
		/// Creates the schema type representing the contents of a trigger type
		/// </summary>
		/// <returns>Type definition for an agent</returns>
		static XmlSchemaType CreateTriggerBodyType()
		{
			XmlSchemaChoice TriggerChoice = new XmlSchemaChoice();
			TriggerChoice.MinOccurs = 0;
			TriggerChoice.MaxOccursString = "unbounded";
			TriggerChoice.Items.Add(CreateSchemaElement("Property", ScriptSchemaStandardType.Property));
			TriggerChoice.Items.Add(CreateSchemaElement("EnvVar", ScriptSchemaStandardType.EnvVar));
			TriggerChoice.Items.Add(CreateSchemaElement("Agent", ScriptSchemaStandardType.Agent));
			TriggerChoice.Items.Add(CreateSchemaElement("Aggregate", ScriptSchemaStandardType.Aggregate));
			TriggerChoice.Items.Add(CreateSchemaElement("Warning", ScriptSchemaStandardType.Warning));
			TriggerChoice.Items.Add(CreateSchemaElement("Error", ScriptSchemaStandardType.Error));
			TriggerChoice.Items.Add(CreateDoElement(ScriptSchemaStandardType.TriggerBody));
			TriggerChoice.Items.Add(CreateSwitchElement(ScriptSchemaStandardType.TriggerBody));
			TriggerChoice.Items.Add(CreateForEachElement(ScriptSchemaStandardType.TriggerBody));

			XmlSchemaComplexType TriggerType = new XmlSchemaComplexType();
			TriggerType.Name = GetTypeName(ScriptSchemaStandardType.TriggerBody);
			TriggerType.Particle = TriggerChoice;
			return TriggerType;
		}
 private bool IsChoiceFromChoiceSubstGroup(XmlSchemaChoice derivedChoice, XmlSchemaChoice baseChoice) {
     if (!IsValidOccurrenceRangeRestriction(derivedChoice, baseChoice)) {
         restrictionErrorMsg = Res.GetString(Res.Sch_GroupBaseRestRangeInvalid);
         return false;
     }
     for (int i = 0; i < derivedChoice.Items.Count; ++i) {
         if (GetMappingParticle((XmlSchemaParticle)derivedChoice.Items[i], baseChoice.Items) < 0) {
             return false;
         }
     }
     return true;
 }
Example #35
0
		/// <summary>
		/// Creates the schema type representing the contents of agent type
		/// </summary>
		/// <returns>Type definition for an agent</returns>
		static XmlSchemaType CreateAgentBodyType()
		{
			XmlSchemaChoice AgentChoice = new XmlSchemaChoice();
			AgentChoice.MinOccurs = 0;
			AgentChoice.MaxOccursString = "unbounded";
			AgentChoice.Items.Add(CreateSchemaElement("Property", ScriptSchemaStandardType.Property));
			AgentChoice.Items.Add(CreateSchemaElement("EnvVar", ScriptSchemaStandardType.EnvVar));
			AgentChoice.Items.Add(CreateSchemaElement("Node", ScriptSchemaStandardType.Node));
			AgentChoice.Items.Add(CreateSchemaElement("Warning", ScriptSchemaStandardType.Warning));
			AgentChoice.Items.Add(CreateSchemaElement("Error", ScriptSchemaStandardType.Error));
			AgentChoice.Items.Add(CreateDoElement(ScriptSchemaStandardType.AgentBody));
			AgentChoice.Items.Add(CreateSwitchElement(ScriptSchemaStandardType.AgentBody));
			AgentChoice.Items.Add(CreateForEachElement(ScriptSchemaStandardType.AgentBody));

			XmlSchemaComplexType AgentType = new XmlSchemaComplexType();
			AgentType.Name = GetTypeName(ScriptSchemaStandardType.AgentBody);
			AgentType.Particle = AgentChoice;
			return AgentType;
		}
 private XmlSchemaParticle CannonicalizeElement(XmlSchemaElement element) {
     if (!element.RefName.IsEmpty && (element.ElementDecl.Block & XmlSchemaDerivationMethod.Substitution) == 0) {
         XmlSchemaSubstitutionGroup substitutionGroup = (XmlSchemaSubstitutionGroup)examplars[element.QualifiedName];
         if (substitutionGroup == null) {
             return element;
         }
         else {
             XmlSchemaChoice choice = new XmlSchemaChoice(); 
             for (int i = 0; i < substitutionGroup.Members.Count; ++i) {
                 choice.Items.Add((XmlSchemaElement)substitutionGroup.Members[i]);
             }
             choice.MinOccurs = element.MinOccurs;
             choice.MaxOccurs = element.MaxOccurs;
             CopyPosition(choice, element, false);
             return choice;
         }
     }
     else {
         return element;
     }
 }
Example #37
0
		/// <summary>
		/// Creates the schema type representing the body of the node type
		/// </summary>
		/// <returns>Type definition for a node</returns>
		static XmlSchemaType CreateNodeBodyType(Dictionary<string, XmlSchemaComplexType> TaskNameToType)
		{
			XmlSchemaChoice NodeChoice = new XmlSchemaChoice();
			NodeChoice.MinOccurs = 0;
			NodeChoice.MaxOccursString = "unbounded";
			NodeChoice.Items.Add(CreateSchemaElement("Property", ScriptSchemaStandardType.Property));
			NodeChoice.Items.Add(CreateSchemaElement("EnvVar", ScriptSchemaStandardType.EnvVar));
			NodeChoice.Items.Add(CreateSchemaElement("Warning", ScriptSchemaStandardType.Warning));
			NodeChoice.Items.Add(CreateSchemaElement("Error", ScriptSchemaStandardType.Error));
			NodeChoice.Items.Add(CreateDoElement(ScriptSchemaStandardType.NodeBody));
			NodeChoice.Items.Add(CreateSwitchElement(ScriptSchemaStandardType.NodeBody));
			NodeChoice.Items.Add(CreateForEachElement(ScriptSchemaStandardType.NodeBody));
			foreach (KeyValuePair<string, XmlSchemaComplexType> Pair in TaskNameToType.OrderBy(x => x.Key))
			{
				NodeChoice.Items.Add(CreateSchemaElement(Pair.Key, new XmlQualifiedName(Pair.Value.Name, NamespaceURI)));
			}

			XmlSchemaComplexType NodeType = new XmlSchemaComplexType();
			NodeType.Name = GetTypeName(ScriptSchemaStandardType.NodeBody);
			NodeType.Particle = NodeChoice;
			return NodeType;
		}
Example #38
0
		void ImportChoiceContent (XmlQualifiedName typeQName, ClassMap cmap, XmlSchemaChoice choice, CodeIdentifiers classIds, bool multiValue)
		{
			XmlTypeMapElementInfoList choices = new XmlTypeMapElementInfoList ();
			multiValue = ImportChoices (typeQName, null, choices, choice.Items) || multiValue;
			if (choices.Count == 0) return;

			if (choice.MaxOccurs > 1) multiValue = true;

			XmlTypeMapMemberElement member;
			if (multiValue)
			{
				member = new XmlTypeMapMemberFlatList ();
				member.Name = classIds.AddUnique ("Items", member);
				ListMap listMap = new ListMap ();
				listMap.ItemInfo = choices;
				((XmlTypeMapMemberFlatList)member).ListMap = listMap;
			}
			else
			{
				member = new XmlTypeMapMemberElement ();
				member.Name = classIds.AddUnique ("Item", member);
			}
			
			// If all choices have the same type, use that type for the member.
			// If not use System.Object.
			// If there are at least two choices with the same type, use a choice
			// identifier attribute

			TypeData typeData = null;
			bool twoEqual = false;
			bool allEqual = true;
			Hashtable types = new Hashtable ();

			for (int n = choices.Count - 1; n >= 0; n--)
			{
				XmlTypeMapElementInfo einfo = (XmlTypeMapElementInfo) choices [n];
				
				// In some complex schemas, we may end up with several options
				// with the same name. It is better to ignore the extra options
				// than to crash. It's the best we can do, and btw it works
				// better than in MS.NET.
				
				if (cmap.GetElement (einfo.ElementName, einfo.Namespace, einfo.ExplicitOrder) != null ||
					choices.IndexOfElement (einfo.ElementName, einfo.Namespace) != n)
				{
					choices.RemoveAt (n);
					continue;
				}
					
				if (types.ContainsKey (einfo.TypeData)) twoEqual = true;
				else types.Add (einfo.TypeData, einfo);

				TypeData choiceType = einfo.TypeData;
				if (choiceType.SchemaType == SchemaTypes.Class)
				{
					// When comparing class types, use the most generic class in the
					// inheritance hierarchy

					XmlTypeMapping choiceMap = GetTypeMapping (choiceType);
					BuildPendingMap (choiceMap);
					while (choiceMap.BaseMap != null) {
						choiceMap = choiceMap.BaseMap;
						BuildPendingMap (choiceMap);
						choiceType = choiceMap.TypeData;
					}
				}
				
				if (typeData == null) typeData = choiceType;
				else if (typeData != choiceType) allEqual = false;
			}

			if (!allEqual)
				typeData = TypeTranslator.GetTypeData (typeof(object));

			if (twoEqual)
			{
				// Create the choice member
				XmlTypeMapMemberElement choiceMember = new XmlTypeMapMemberElement ();
				choiceMember.Ignore = true;
				choiceMember.Name = classIds.AddUnique (member.Name + "ElementName", choiceMember);
				member.ChoiceMember = choiceMember.Name;

				// Create the choice enum
				XmlTypeMapping enumMap = CreateTypeMapping (new XmlQualifiedName (member.Name + "ChoiceType", typeQName.Namespace), SchemaTypes.Enum, null);
				enumMap.IncludeInSchema = false;

				CodeIdentifiers codeIdents = new CodeIdentifiers ();
				EnumMap.EnumMapMember[] members = new EnumMap.EnumMapMember [choices.Count];
				for (int n=0; n<choices.Count; n++)
				{
					XmlTypeMapElementInfo it =(XmlTypeMapElementInfo) choices[n];
					bool extraNs = (it.Namespace != null && it.Namespace != "" && it.Namespace != typeQName.Namespace);
					string xmlName = extraNs ? it.Namespace + ":" + it.ElementName : it.ElementName;
					string enumName = codeIdents.AddUnique (CodeIdentifier.MakeValid (it.ElementName), it);
					members [n] = new EnumMap.EnumMapMember (xmlName, enumName);
				}
				enumMap.ObjectMap = new EnumMap (members, false);

				choiceMember.TypeData = multiValue ? enumMap.TypeData.ListTypeData : enumMap.TypeData;
				choiceMember.ElementInfo.Add (CreateElementInfo (typeQName.Namespace, choiceMember, choiceMember.Name, choiceMember.TypeData, false, XmlSchemaForm.None, -1));
				cmap.AddMember (choiceMember);
			}
			
			if (typeData == null)
				return;
	
			if (multiValue)
				typeData = typeData.ListTypeData;

			member.ElementInfo = choices;
			member.Documentation = GetDocumentation (choice);
			member.TypeData = typeData;
			cmap.AddMember (member);
		}
Example #39
0
            protected XmlSchemaComplexType CreateTaskListComplexType(Type[] tasks, Type[] dataTypes, bool includeProjectLevelItems)
            {
                XmlSchemaComplexType tasklistCT = new XmlSchemaComplexType();
                XmlSchemaChoice choice = new XmlSchemaChoice();
                choice.MinOccurs = 0;
                choice.MaxOccursString = "unbounded";

                tasklistCT.Particle = choice;

                foreach (Type t in tasks) {
                    XmlSchemaElement taskElement = new XmlSchemaElement();
                    string typeId = GenerateIDFromType(t);
                    XmlSchemaComplexType taskCT = FindComplexTypeByID(typeId);

                    taskElement.Name = GetTaskName(t);
                    taskElement.SchemaTypeName = taskCT.QualifiedName;

                    choice.Items.Add(taskElement);
                }

                foreach (Type t in dataTypes) {
                    XmlSchemaElement dataTypeElement = new XmlSchemaElement();
                    string typeId = GenerateIDFromType(t);
                    XmlSchemaComplexType dataTypeCT = FindComplexTypeByID(typeId);

                    dataTypeElement.Name = GetDataTypeName(t);
                    dataTypeElement.SchemaTypeName = dataTypeCT.QualifiedName;

                    choice.Items.Add(dataTypeElement);
                }

                if (includeProjectLevelItems) {
                    XmlSchemaElement targetElement = new XmlSchemaElement();

                    targetElement.Name = "target";
                    targetElement.SchemaTypeName = _targetCT.QualifiedName;

                    choice.Items.Add(targetElement);
                }

                // allow elements from other namespaces
                XmlSchemaAny otherNamespaceAny = new XmlSchemaAny();
                otherNamespaceAny.MinOccurs = 0;
                otherNamespaceAny.MaxOccurs = Decimal.MaxValue;
                otherNamespaceAny.Namespace = "##other";
                otherNamespaceAny.ProcessContents = XmlSchemaContentProcessing.Strict;
                choice.Items.Add(otherNamespaceAny);

                return tasklistCT;
            }
        //<extension
        //  base = QName
        //  id = ID
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, ((group | all | choice | sequence)?, ((attribute | attributeGroup)*, anyAttribute?)))
        //</extension>
        internal static XmlSchemaComplexContentExtension Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaComplexContentExtension extension = new XmlSchemaComplexContentExtension();

            reader.MoveToElement();

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

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

            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "base")
                {
                    Exception innerex;
                    extension.baseTypeName = XmlSchemaUtil.ReadQNameAttribute(reader, out innerex);
                    if (innerex != null)
                    {
                        error(h, reader.Value + " is not a valid value for base attribute", innerex);
                    }
                }
                else if (reader.Name == "id")
                {
                    extension.Id = reader.Value;
                }
                else if ((reader.NamespaceURI == "" && reader.Name != "xmlns") || reader.NamespaceURI == XmlSchema.Namespace)
                {
                    error(h, reader.Name + " is not a valid attribute for extension", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, extension);
                }
            }

            reader.MoveToElement();
            if (reader.IsEmptyElement)
            {
                return(extension);
            }
            //Content: 1. annotation?,
            //			(2.(group | all | choice | sequence)?, (3.(attribute | attributeGroup)*, 4.anyAttribute?)))
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaComplexContentExtension.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)
                    {
                        extension.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2)
                {
                    if (reader.LocalName == "group")
                    {
                        level = 3;
                        XmlSchemaGroupRef group = XmlSchemaGroupRef.Read(reader, h);
                        if (group != null)
                        {
                            extension.particle = group;
                        }
                        continue;
                    }
                    if (reader.LocalName == "all")
                    {
                        level = 3;
                        XmlSchemaAll all = XmlSchemaAll.Read(reader, h);
                        if (all != null)
                        {
                            extension.particle = all;
                        }
                        continue;
                    }
                    if (reader.LocalName == "choice")
                    {
                        level = 3;
                        XmlSchemaChoice choice = XmlSchemaChoice.Read(reader, h);
                        if (choice != null)
                        {
                            extension.particle = choice;
                        }
                        continue;
                    }
                    if (reader.LocalName == "sequence")
                    {
                        level = 3;
                        XmlSchemaSequence sequence = XmlSchemaSequence.Read(reader, h);
                        if (sequence != null)
                        {
                            extension.particle = sequence;
                        }
                        continue;
                    }
                }
                if (level <= 3)
                {
                    if (reader.LocalName == "attribute")
                    {
                        level = 3;
                        XmlSchemaAttribute attr = XmlSchemaAttribute.Read(reader, h);
                        if (attr != null)
                        {
                            extension.Attributes.Add(attr);
                        }
                        continue;
                    }
                    if (reader.LocalName == "attributeGroup")
                    {
                        level = 3;
                        XmlSchemaAttributeGroupRef attr = XmlSchemaAttributeGroupRef.Read(reader, h);
                        if (attr != null)
                        {
                            extension.attributes.Add(attr);
                        }
                        continue;
                    }
                }
                if (level <= 4 && reader.LocalName == "anyAttribute")
                {
                    level = 5;
                    XmlSchemaAnyAttribute anyattr = XmlSchemaAnyAttribute.Read(reader, h);
                    if (anyattr != null)
                    {
                        extension.AnyAttribute = anyattr;
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(extension);
        }
Example #41
0
        MemberMapping ImportChoiceGroup(XmlSchemaChoice group, string identifier, CodeIdentifiers members, string ns, bool groupRepeats) {
            ArrayList list = new ArrayList();
            if (GatherGroupChoices(group, list, identifier, ns))
                groupRepeats = true;
            MemberMapping member = new MemberMapping();
            member.Elements = (ElementAccessor[])list.ToArray(typeof(ElementAccessor));

            bool duplicateTypes = false;
            Hashtable uniqueTypeDescs = new Hashtable(list.Count);

            for (int i = 0; i < list.Count; i++) {
                TypeDesc td = ((TypeMapping)((ElementAccessor)list[i]).Mapping).TypeDesc;
                if (uniqueTypeDescs.Contains(td.FullName)) {
                    duplicateTypes = true;
                }
                else {
                    uniqueTypeDescs.Add(td.FullName, td);
                }
            }
            TypeDesc[] typeDescs = new TypeDesc[uniqueTypeDescs.Count];
            uniqueTypeDescs.Values.CopyTo(typeDescs, 0);
            member.TypeDesc = TypeDesc.FindCommonBaseTypeDesc(typeDescs);
            if (member.TypeDesc == null) member.TypeDesc = scope.GetTypeDesc(typeof(object));

            if (groupRepeats)
                member.TypeDesc = member.TypeDesc.CreateArrayTypeDesc();

            if (members != null) {
                member.Name = members.AddUnique(groupRepeats ? "Items" : "Item", member);
            }

            if (duplicateTypes) {
                member.ChoiceIdentifier = new ChoiceIdentifierAccessor();
                member.ChoiceIdentifier.MemberName = member.Name + "ElementName";
                // we need to create the EnumMapping to store all of the element names
                member.ChoiceIdentifier.Mapping = ImportEnumeratedChoice(member.Elements, ns, member.Name + "ChoiceType");
                member.ChoiceIdentifier.MemberIds = new string[member.Elements.Length];
                ConstantMapping[] constants = ((EnumMapping)member.ChoiceIdentifier.Mapping).Constants;
                for (int i = 0; i < member.Elements.Length; i++) {
                    member.ChoiceIdentifier.MemberIds[i] = constants[i].Name;
                }
                MemberMapping choiceIdentifier = new MemberMapping();
                choiceIdentifier.Ignore = true;
                choiceIdentifier.Name = member.ChoiceIdentifier.MemberName;
                if (groupRepeats) {
                    choiceIdentifier.TypeDesc = member.ChoiceIdentifier.Mapping.TypeDesc.CreateArrayTypeDesc();
                }
                else {
                    choiceIdentifier.TypeDesc = member.ChoiceIdentifier.Mapping.TypeDesc;
                }

                // create element accessor for the choiceIdentifier

                ElementAccessor choiceAccessor = new ElementAccessor();
                choiceAccessor.Name = choiceIdentifier.Name;
                choiceAccessor.Namespace = ns;
                choiceAccessor.Mapping =  member.ChoiceIdentifier.Mapping;
                choiceIdentifier.Elements  = new ElementAccessor[] {choiceAccessor};

                if (members != null) {
                    choiceAccessor.Name = choiceIdentifier.Name = member.ChoiceIdentifier.MemberName = members.AddUnique(member.ChoiceIdentifier.MemberName, choiceIdentifier);
                }
            }
            return member;
        }
 private bool IsSequenceFromChoice(XmlSchemaSequence derivedSequence, XmlSchemaChoice baseChoice)
 {
     decimal num;
     decimal num2;
     this.CalculateSequenceRange(derivedSequence, out num, out num2);
     if (!this.IsValidOccurrenceRangeRestriction(num, num2, baseChoice.MinOccurs, baseChoice.MaxOccurs) || (derivedSequence.Items.Count > baseChoice.Items.Count))
     {
         return false;
     }
     for (int i = 0; i < derivedSequence.Items.Count; i++)
     {
         if (this.GetMappingParticle((XmlSchemaParticle) derivedSequence.Items[i], baseChoice.Items) < 0)
         {
             return false;
         }
     }
     return true;
 }
Example #43
0
 void ImportAbstractMember(XmlSchemaElement element, string identifier, CodeIdentifiers members, string ns, bool repeats) {
     XmlSchemaElement[] elements = GetEquivalentElements(element);
     XmlSchemaChoice choice = new XmlSchemaChoice();
     for (int i = 0; i < elements.Length; i++)
         choice.Items.Add(elements[i]);
     if (identifier.Length == 0)
         identifier = CodeIdentifier.MakeValid(Accessor.UnescapeName(element.Name));
     else
         identifier += CodeIdentifier.MakePascal(Accessor.UnescapeName(element.Name));
     ImportChoiceGroup(choice, identifier, members, ns, repeats);
 }
Example #44
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);
                }
            
            }
Example #45
0
        void ExportElementAccessors(XmlSchemaGroupBase group, ElementAccessor[] accessors, bool repeats, bool valueTypeOptional, string ns) {
            if (accessors.Length == 0) return;
            if (accessors.Length == 1) {
                ExportElementAccessor(group, accessors[0], repeats, valueTypeOptional, ns);
            }
            else {
                XmlSchemaChoice choice = new XmlSchemaChoice();
                choice.MaxOccurs = repeats ? decimal.MaxValue : 1;
                choice.MinOccurs = repeats ? 0 : 1;
                for (int i = 0; i < accessors.Length; i++)
                    ExportElementAccessor(choice, accessors[i], false, valueTypeOptional, ns);

                if (choice.Items.Count > 0) group.Items.Add(choice);
            }
        }