상속: XmlSchemaGroupBase
예제 #1
0
        private sch.XmlSchemaAll GenOneTabElement(sch.XmlSchemaAll curElement, string tableAlias, List <string> tabCols, List <string> tabColTypes)
        {
            sch.XmlSchemaElement rootElement = new sch.XmlSchemaElement();
            rootElement.Name            = tableAlias;
            rootElement.MinOccurs       = 0;
            rootElement.MaxOccursString = "unbounded";
            curElement.Items.Add(rootElement);

            sch.XmlSchemaComplexType rootType = new sch.XmlSchemaComplexType();
            rootType.IsMixed = false;
            sch.XmlSchemaAll rootAll = new sch.XmlSchemaAll();
            rootType.Particle      = rootAll;
            rootElement.SchemaType = rootType;

            for (int i = 0; i < tabCols.Count; i++)
            {
                string colName = tabCols[i];
                string type    = tabColTypes[i];
                sch.XmlSchemaElement column = new sch.XmlSchemaElement();
                column.Name           = colName;
                column.SchemaTypeName = new XmlQualifiedName(type, ns);
                rootAll.Items.Add(column);
            }
            return(rootAll);
        }
예제 #2
0
        internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle,
                                                               ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            XmlSchemaAny any        = baseParticle as XmlSchemaAny;
            XmlSchemaAll derivedAll = baseParticle as XmlSchemaAll;

            if (any != null)
            {
                // NSRecurseCheckCardinality
                return(ValidateNSRecurseCheckCardinality(any, h, schema, raiseError));
            }
            else if (derivedAll != null)
            {
                // Recurse
                if (!ValidateOccurenceRangeOK(derivedAll, h, schema, raiseError))
                {
                    return(false);
                }
                return(ValidateRecurse(derivedAll, h, schema, raiseError));
            }
            else
            {
                if (raiseError)
                {
                    error(h, "Invalid -all- particle derivation was found.");
                }
                return(false);
            }
        }
예제 #3
0
        //gen new xsd base on selected tables and columns which generated by OSQL.
        private string CreateXsd()
        {
            xmlschema = new sch.XmlSchema();

            //Create the PdeData element
            sch.XmlSchemaElement rootElement = new sch.XmlSchemaElement();
            rootElement.Name = "PdeData";
            xmlschema.Items.Add(rootElement);
            sch.XmlSchemaComplexType rootType = new sch.XmlSchemaComplexType();
            rootType.IsMixed = false;
            sch.XmlSchemaAll rootAll = new sch.XmlSchemaAll();
            rootType.Particle      = rootAll;
            rootElement.SchemaType = rootType;

            for (int i = 0; i < selectedTables.Count; i++)
            {
                rootAll = GenOneTabElement(rootAll, selectedTables[i], selectedColumns[i], tabColsType[i]);
            }

            xmlschema.Compile(new sch.ValidationEventHandler(ValidationEventHandler));
            FileStream stream = new FileStream("e:\\temp.xsd", FileMode.Create);

            //Write the file
            xmlschema.Write(stream);
            stream.Close();

            return("e:\\temp.xsd");
        }
예제 #4
0
        private void NavigateAll(XmlSchemaAll all)
        {
            handler.BeginAll(all);

            NavigateObjectCollection(all.Items);

            handler.EndAll();
        }
예제 #5
0
        private string genExpXsd()
        {
            sch.XmlSchema expSchema = new sch.XmlSchema();

            //Create the PdeData element
            sch.XmlSchemaElement rootElement = new sch.XmlSchemaElement();
            rootElement.Name = ROOT_ELEMENT;
            expSchema.Items.Add(rootElement);
            sch.XmlSchemaComplexType rootType = new sch.XmlSchemaComplexType();
            rootType.IsMixed = false;
            sch.XmlSchemaSequence rootSequence = new sch.XmlSchemaSequence();
            rootType.Particle      = rootSequence;
            rootElement.SchemaType = rootType;

            foreach (ExportItemMap itemMap in exportItems)
            {
                if (itemMap.mapType == ProntoDoc.Framework.CoreObject.MapType.singleCell)
                {
                    sch.XmlSchemaElement item = new sch.XmlSchemaElement();
                    item.Name           = itemMap.treeNodeName;
                    item.SchemaTypeName = new XmlQualifiedName(itemMap.dataType, ns);
                    rootSequence.Items.Add(item);
                }
                else
                {
                    sch.XmlSchemaElement tabElement = new sch.XmlSchemaElement();
                    tabElement.MinOccurs       = 0;
                    tabElement.MaxOccursString = "unbounded";
                    tabElement.Name            = itemMap.treeNodeName;
                    rootSequence.Items.Add(tabElement);

                    sch.XmlSchemaComplexType tabType = new sch.XmlSchemaComplexType();
                    tabType.IsMixed = false;
                    sch.XmlSchemaAll tabAll = new sch.XmlSchemaAll();
                    tabType.Particle      = tabAll;
                    tabElement.SchemaType = tabType;

                    //generate children node
                    foreach (TableColumnMap col in itemMap.tabCols)
                    {
                        sch.XmlSchemaElement item = new sch.XmlSchemaElement();
                        item.Name           = col.treeNodeName;
                        item.SchemaTypeName = new XmlQualifiedName(col.dataType, ns);
                        tabAll.Items.Add(item);
                    }
                }
            }

            expSchema.Compile(new sch.ValidationEventHandler(ValidationEventHandler));
            FileStream stream = new FileStream("e:\\tempout.xsd", FileMode.Create);

            //Write the file
            expSchema.Write(stream);
            stream.Close();

            return("e:\\tempout.xsd");
        }
예제 #6
0
        private Schema.XmlSchemaAll CreateElement(Schema.XmlSchemaSequence parent, string name)
        {
            Schema.XmlSchemaElement element = new Schema.XmlSchemaElement();
            element.MinOccurs       = 0;
            element.MaxOccursString = "unbounded";
            element.Name            = name;
            parent.Items.Add(element);

            Schema.XmlSchemaComplexType type = new Schema.XmlSchemaComplexType();
            type.IsMixed = false;
            Schema.XmlSchemaAll elementAll = new Schema.XmlSchemaAll();
            type.Particle      = elementAll;
            element.SchemaType = type;

            return(elementAll);
        }
예제 #7
0
        internal override XmlSchemaParticle GetOptimizedParticle(bool isTop)
        {
            if (OptimizedParticle != null)
            {
                return(OptimizedParticle);
            }
            if (Items.Count == 0 || ValidatedMaxOccurs == 0)
            {
                OptimizedParticle = XmlSchemaParticle.Empty;
                return(OptimizedParticle);
            }
            else if (Items.Count == 1)
            {
                if (ValidatedMinOccurs == 1 && ValidatedMaxOccurs == 1)
                {
                    XmlSchemaSequence seq = new XmlSchemaSequence();
                    this.CopyInfo(seq);
                    XmlSchemaParticle p = (XmlSchemaParticle)Items [0];
                    p = p.GetOptimizedParticle(false);
                    if (p == XmlSchemaParticle.Empty)
                    {
                        OptimizedParticle = p;
                    }
                    else
                    {
                        seq.Items.Add(p);
                        seq.CompiledItems.Add(p);
                        seq.Compile(null, schema);
                        OptimizedParticle = seq;
                    }
                    return(OptimizedParticle);
                }
            }

            XmlSchemaAll all = new XmlSchemaAll();

            CopyInfo(all);
            CopyOptimizedItems(all);
            OptimizedParticle = all;
            all.ComputeEmptiable();

            return(OptimizedParticle);
        }
예제 #8
0
        internal override bool ValidateDerivationByRestriction(XmlSchemaParticle baseParticle, ValidationEventHandler h, XmlSchema schema, bool raiseError)
        {
            XmlSchemaAny xmlSchemaAny = baseParticle as XmlSchemaAny;
            XmlSchemaAll xmlSchemaAll = baseParticle as XmlSchemaAll;

            if (xmlSchemaAny != null)
            {
                return(base.ValidateNSRecurseCheckCardinality(xmlSchemaAny, h, schema, raiseError));
            }
            if (xmlSchemaAll != null)
            {
                return(this.ValidateOccurenceRangeOK(xmlSchemaAll, h, schema, raiseError) && base.ValidateRecurse(xmlSchemaAll, h, schema, raiseError));
            }
            if (raiseError)
            {
                base.error(h, "Invalid -all- particle derivation was found.");
            }
            return(false);
        }
예제 #9
0
        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;
                return(this.OptimizedParticle);
            }
            if (this.Items.Count == 1 && base.ValidatedMinOccurs == 1m && base.ValidatedMaxOccurs == 1m)
            {
                XmlSchemaSequence xmlSchemaSequence = new XmlSchemaSequence();
                this.CopyInfo(xmlSchemaSequence);
                XmlSchemaParticle xmlSchemaParticle = (XmlSchemaParticle)this.Items[0];
                xmlSchemaParticle = xmlSchemaParticle.GetOptimizedParticle(false);
                if (xmlSchemaParticle == XmlSchemaParticle.Empty)
                {
                    this.OptimizedParticle = xmlSchemaParticle;
                }
                else
                {
                    xmlSchemaSequence.Items.Add(xmlSchemaParticle);
                    xmlSchemaSequence.CompiledItems.Add(xmlSchemaParticle);
                    xmlSchemaSequence.Compile(null, this.schema);
                    this.OptimizedParticle = xmlSchemaSequence;
                }
                return(this.OptimizedParticle);
            }
            XmlSchemaAll xmlSchemaAll = new XmlSchemaAll();

            this.CopyInfo(xmlSchemaAll);
            base.CopyOptimizedItems(xmlSchemaAll);
            this.OptimizedParticle = xmlSchemaAll;
            xmlSchemaAll.ComputeEmptiable();
            return(this.OptimizedParticle);
        }
        protected internal override void Write(XmlSchemaObject obj)
        {
            var type = obj as XmlSchemaComplexType;
            if (type != null)
            {
                type.Name = Name;
                var all = new XmlSchemaAll();

                foreach (var prop in Properties)
                {
                    var element = new XmlSchemaElement();
                    prop.Write(element);
                    all.Items.Add(element);
                }

                if (BaseType != null)
                {
                    type.ContentModel = new XmlSchemaComplexContent
                                        {
                                            Content = new XmlSchemaComplexContentExtension
                                                      {
                                                          BaseTypeName = BaseType.QualifiedName,
                                                          AnyAttribute = AnyAttribute,
                                                          Particle = all
                                                      }
                                        };
                }
                else
                {
                    type.AnyAttribute = AnyAttribute;
                    type.Particle = all;
                }
            }

            base.Write(obj);
        }
 private bool IsSequenceFromAll(XmlSchemaSequence derivedSequence, XmlSchemaAll baseAll) {
     if (!IsValidOccurrenceRangeRestriction(derivedSequence, baseAll) || derivedSequence.Items.Count > baseAll.Items.Count) {
         return false;
     }
     BitSet map = new BitSet(baseAll.Items.Count);
     for (int j = 0; j < derivedSequence.Items.Count; ++j) {
         int i = GetMappingParticle((XmlSchemaParticle)derivedSequence.Items[j], baseAll.Items);
         if (i >= 0) {
             if (map[i]) {
                 return false;
             }
             else {
                 map.Set(i);
             }
         }
         else {
             return false;
         }
     }
     for (int i = 0; i < baseAll.Items.Count; i++) {
         if (!map[i] && !IsParticleEmptiable((XmlSchemaParticle)baseAll.Items[i])) {
             return false;
         }
     }
     return true;
 }
 private XmlSchemaParticle CannonicalizeAll(XmlSchemaAll all, bool root) {
     if (all.Items.Count > 0) {
         XmlSchemaAll newAll = new XmlSchemaAll();
         newAll.MinOccurs = all.MinOccurs;
         newAll.MaxOccurs = all.MaxOccurs;
         CopyPosition(newAll, all, true);
         for (int i = 0; i < all.Items.Count; ++i) {
             XmlSchemaParticle p = CannonicalizeParticle((XmlSchemaElement)all.Items[i], false);
             if (p != XmlSchemaParticle.Empty) {
                 newAll.Items.Add(p);
             }
         }
         all = newAll;
     }
     if (all.Items.Count == 0) {
         return XmlSchemaParticle.Empty;
     }
     else if (!root) {
         SendValidationEvent(Res.Sch_NotAllAlone, all);
         return XmlSchemaParticle.Empty;
     }
     else {
         return all;
     }
 }
 private void Write55_XmlSchemaAll(string n, string ns, XmlSchemaAll o, bool isNullable, bool needType)
 {
     if (o == null)
     {
         if (isNullable)
         {
             base.WriteNullTagLiteral(n, ns);
         }
     }
     else
     {
         if (!needType && !(o.GetType() == typeof(XmlSchemaAll)))
         {
             throw base.CreateUnknownTypeException(o);
         }
         base.EscapeName = false;
         base.WriteStartElement(n, ns, o, false, o.Namespaces);
         if (needType)
         {
             base.WriteXsiType("XmlSchemaAll", "http://www.w3.org/2001/XMLSchema");
         }
         base.WriteAttribute("id", "", o.Id);
         XmlAttribute[] unhandledAttributes = o.UnhandledAttributes;
         if (unhandledAttributes != null)
         {
             for (int i = 0; i < unhandledAttributes.Length; i++)
             {
                 XmlAttribute node = unhandledAttributes[i];
                 base.WriteXmlAttribute(node, o);
             }
         }
         base.WriteAttribute("minOccurs", "", o.MinOccursString);
         base.WriteAttribute("maxOccurs", "", o.MaxOccursString);
         this.Write11_XmlSchemaAnnotation("annotation", "http://www.w3.org/2001/XMLSchema", o.Annotation, false, false);
         XmlSchemaObjectCollection items = o.Items;
         if (items != null)
         {
             for (int j = 0; j < items.Count; j++)
             {
                 this.Write52_XmlSchemaElement("element", "http://www.w3.org/2001/XMLSchema", (XmlSchemaElement) items[j], false, false);
             }
         }
         base.WriteEndElement(o);
     }
 }
예제 #14
0
 void Handler.BeginAll(XmlSchemaAll all)
 {
 }
예제 #15
0
 private void GenerateAll(XmlSchemaAll all, InstanceGroup grp)
 {
     XmlSchemaParticle pt;
     for (int i=all.Items.Count; i > 0; i--) {
         pt = (XmlSchemaParticle)(all.Items[i-1]);
         GenerateParticle(pt,false, grp);
     }
 }
        //<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);
        }
예제 #17
0
		internal override bool ValidateDerivationByRestriction (XmlSchemaParticle baseParticle,
			ValidationEventHandler h, XmlSchema schema, bool raiseError)
		{
			// element - NameAndTypeOK
			XmlSchemaElement baseElement = baseParticle as XmlSchemaElement;
			if (baseElement != null) {
				return ValidateDerivationByRestrictionNameAndTypeOK (baseElement, h, schema, raiseError);
			}

			// any - NSCompat
			XmlSchemaAny baseAny = baseParticle as XmlSchemaAny;
			if (baseAny != null) {
				// NSCompat
				if (!baseAny.ValidateWildcardAllowsNamespaceName (this.QualifiedName.Namespace, h, schema, raiseError))
					return false;
				return ValidateOccurenceRangeOK (baseAny, h, schema, raiseError);
			}

//*
			// choice - RecurseAsIfGroup
			XmlSchemaGroupBase gb = null;
			if (baseParticle is XmlSchemaSequence)
				gb = new XmlSchemaSequence ();
			else if (baseParticle is XmlSchemaChoice)
				gb = new XmlSchemaChoice ();
			else if (baseParticle is XmlSchemaAll)
				gb = new XmlSchemaAll ();

			if (gb != null) {
				gb.Items.Add (this);
				gb.Compile (h, schema);
				gb.Validate (h, schema);
				// It looks weird, but here we never think about 
				// _pointlessness_ of this groupbase particle.
				return gb.ValidateDerivationByRestriction (baseParticle, h, schema, raiseError);
			}
//*/
			return true;
		}
 private void Write43_XmlSchemaAll(XmlSchemaAll o)
 {
     if (o != null)
     {
         this.WriteStartElement("all");
         this.WriteAttribute("id", "", o.Id);
         this.WriteAttribute("minOccurs", "", XmlConvert.ToString(o.MinOccurs));
         this.WriteAttribute("maxOccurs", "", (o.MaxOccurs == 79228162514264337593543950335M) ? "unbounded" : XmlConvert.ToString(o.MaxOccurs));
         this.WriteAttributes(o.UnhandledAttributes, o);
         this.Write5_XmlSchemaAnnotation(o.Annotation);
         this.WriteSortedItems(o.Items);
         this.WriteEndElement();
     }
 }
예제 #19
0
 IEnumerable<XElement> CreateProtoAll(XmlSchemaAll all) {
     foreach (XmlSchemaParticle particle in all.Items) {
         if (((int)particle.MinOccurs) > 0) {
             foreach (var val in CreateProtoParticle(particle).Repeat((int)particle.MinOccurs)) {
                 yield return val;
             }
         }
     }
 }
예제 #20
0
 protected virtual void Visit(XmlSchemaAll particle)
 {
     if (particle.MaxOccurs > 0)
         Traverse(particle.Items);
 }
예제 #21
0
        private string GenExportedXSD(string stnName, PdeExports pdeExports)
        {
            // initialize schema
            string schemaNamespace = "http://www.w3.org/2001/XMLSchema";

            Schema.XmlSchema expSchema = new Schema.XmlSchema();

            // create STN node (root node)
            Schema.XmlSchemaSequence stnElementSequence = CreateSequenceElement(expSchema, stnName);
            Schema.XmlSchemaAll      field = null;
            Schema.XmlSchemaAll      table = null;

            foreach (DomainExportItem expDomain in pdeExports.Items)
            {
                if (expDomain.Items == null || expDomain.Items.Count == 0)
                {
                    continue;
                }

                foreach (ExportItem expItem in expDomain.Items)
                {
                    if (!expItem.IsUsed)
                    {
                        continue;
                    }

                    switch (expItem.MapType)
                    {
                    case MapType.SingleCell:
                        #region field
                        if (field == null)
                        {
                            field = CreateElement(stnElementSequence, MarkupConstant.PdeExportField);
                        }

                        // create field informations
                        Schema.XmlSchemaElement fieldElement = new Schema.XmlSchemaElement();
                        fieldElement.Name           = expItem.EncodeTreeNodeName;
                        fieldElement.SchemaTypeName = new System.Xml.XmlQualifiedName(GetXsdDataType(expItem.DataType), schemaNamespace);
                        field.Items.Add(fieldElement);
                        #endregion
                        break;

                    case MapType.Table:
                        #region table
                        if (table == null)
                        {
                            table = CreateElement(stnElementSequence, MarkupConstant.PdeExportTable);
                        }

                        // create table informations
                        Schema.XmlSchemaElement tableElement = new Schema.XmlSchemaElement();
                        tableElement.MinOccurs       = 0;
                        tableElement.MaxOccursString = "unbounded";
                        tableElement.Name            = expItem.EncodeTreeNodeName;
                        table.Items.Add(tableElement);

                        Schema.XmlSchemaComplexType tableElementType = new Schema.XmlSchemaComplexType();
                        tableElementType.IsMixed = false;
                        Schema.XmlSchemaAll tableElementAll = new Schema.XmlSchemaAll();
                        tableElementType.Particle = tableElementAll;
                        tableElement.SchemaType   = tableElementType;

                        // gen column informations
                        if (expItem.Columns != null && expItem.Columns.Count > 0)
                        {
                            foreach (ColumnExportItem col in expItem.Columns)
                            {
                                if (!col.IsUsed)
                                {
                                    continue;
                                }
                                Schema.XmlSchemaElement colElement = new Schema.XmlSchemaElement();
                                colElement.Name           = col.EncodeTreeNodeName;
                                colElement.SchemaTypeName = new System.Xml.XmlQualifiedName(GetXsdDataType(col.DataType), schemaNamespace);
                                tableElementAll.Items.Add(colElement);
                            }
                        }
                        #endregion
                        break;

                    case MapType.Chart:
                        break;

                    default:
                        break;
                    }
                }
            }

            // complie schema
            expSchema.Compile(new Schema.ValidationEventHandler(ValidationEventHandler));

            // write schem to xsd file
            string xsdFilePath = string.Format("{0}\\{1}.xsd", AssetManager.FileAdapter.TemporaryFolderPath, Guid.NewGuid().ToString());
            using (System.IO.FileStream stream = new System.IO.FileStream(xsdFilePath, System.IO.FileMode.Create))
            {
                expSchema.Write(stream);
                stream.Close();
            }

            return(xsdFilePath);
        }
예제 #22
0
        private string SchemaSearching(XmlSchema xmlSchema, string inputParamType)
        {
            string       returnval = null;
            XmlGenerator xmlGen    = new XmlGenerator();

            foreach (object item in xmlSchema.Items)
            {
                System.Xml.Schema.XmlSchemaElement schemaElement = item as System.Xml.Schema.XmlSchemaElement;
                if (schemaElement != null)
                {
                    if (schemaElement.Name == inputParamType)
                    {
                        returnval = xmlGen.GenerateXmlString(schemaElement, xmlSchema);
                        break;//The parameter was found no need to go through rest of elements
                    }
                }
                else
                { //This is a complex Type
                    System.Xml.Schema.XmlSchemaComplexType complexType = item as System.Xml.Schema.XmlSchemaComplexType;
                    if (complexType != null)
                    {
                        if (complexType.Name == inputParamType)
                        {
                            Logger.Text += "Complex Type Name : " + complexType.Name + "\r\n";
                            System.Xml.Schema.XmlSchemaParticle particle  = complexType.Particle;
                            System.Xml.Schema.XmlSchemaSequence sequence  = particle as System.Xml.Schema.XmlSchemaSequence;
                            System.Xml.Schema.XmlSchemaAll      schemaall = particle as System.Xml.Schema.XmlSchemaAll;
                            if (sequence != null)
                            {
                                foreach (System.Xml.Schema.XmlSchemaElement childElement in sequence.Items)
                                {
                                    string parameterName = childElement.Name;
                                    string parameterType = childElement.SchemaTypeName.Name;
                                    returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(childElement, xmlSchema) + "</" + complexType.Name + '>';
                                }
                            }
                            else
                            {
                                if (schemaall != null)
                                {
                                    returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(schemaall, xmlSchema) + "</" + complexType.Name + '>';
                                }
                                else
                                {
                                    System.Xml.Schema.XmlSchemaComplexContent cmplxContent = null;
                                    if (cmplxContent != null)
                                    {
                                        returnval = '<' + complexType.Name + '>' + xmlGen.GenerateXmlString(cmplxContent, xmlSchema) + "</" + complexType.Name + '>';;
                                    }
                                }
                            }
                            break;  //The parameter was found no need to go through rest of elements
                        }
                    }
                    else
                    {   //Nothing to do?
                        //System.Xml.Schema.XmlSchemaSimpleType simpleType = item as System.Xml.Schema.XmlSchemaSimpleType;
                    }
                }
            }
            return(returnval);
        }
 private XmlSchemaParticle CannonicalizeAll(XmlSchemaAll all, bool root, bool substitution)
 {
     if (all.Items.Count > 0)
     {
         XmlSchemaAll all2 = new XmlSchemaAll {
             MinOccurs = all.MinOccurs,
             MaxOccurs = all.MaxOccurs,
             SourceUri = all.SourceUri,
             LineNumber = all.LineNumber,
             LinePosition = all.LinePosition
         };
         for (int i = 0; i < all.Items.Count; i++)
         {
             XmlSchemaParticle item = this.CannonicalizeParticle((XmlSchemaElement) all.Items[i], false, substitution);
             if (item != XmlSchemaParticle.Empty)
             {
                 all2.Items.Add(item);
             }
         }
         all = all2;
     }
     if (all.Items.Count == 0)
     {
         return XmlSchemaParticle.Empty;
     }
     if (root && (all.Items.Count == 1))
     {
         XmlSchemaSequence sequence = new XmlSchemaSequence {
             MinOccurs = all.MinOccurs,
             MaxOccurs = all.MaxOccurs
         };
         sequence.Items.Add((XmlSchemaParticle) all.Items[0]);
         return sequence;
     }
     if ((!root && (all.Items.Count == 1)) && ((all.MinOccurs == 1M) && (all.MaxOccurs == 1M)))
     {
         return (XmlSchemaParticle) all.Items[0];
     }
     if (!root)
     {
         base.SendValidationEvent("Sch_NotAllAlone", all);
         return XmlSchemaParticle.Empty;
     }
     return all;
 }
예제 #24
0
        //<all
        //  id = ID
        //  maxOccurs = 1 : 1
        //  minOccurs = (0 | 1) : 1
        //  {any attributes with non-schema namespace . . .}>
        //  Content: (annotation?, element*)
        //</all>
        internal static XmlSchemaAll Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAll all = new XmlSchemaAll();

            reader.MoveToElement();

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

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

            //Read Attributes
            while (reader.MoveToNextAttribute())
            {
                if (reader.Name == "id")
                {
                    all.Id = reader.Value;
                }
                else if (reader.Name == "maxOccurs")
                {
                    try
                    {
                        all.MaxOccursString = reader.Value;
                    }
                    catch (Exception e)
                    {
                        error(h, reader.Value + " is an invalid value for maxOccurs", e);
                    }
                }
                else if (reader.Name == "minOccurs")
                {
                    try
                    {
                        all.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 all", null);
                }
                else
                {
                    XmlSchemaUtil.ReadUnhandledAttribute(reader, all);
                }
            }

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

            //Content: (annotation?, element*)
            int level = 1;

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != xmlname)
                    {
                        error(h, "Should not happen :2: XmlSchemaAll.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)
                    {
                        all.Annotation = annotation;
                    }
                    continue;
                }
                if (level <= 2 && reader.LocalName == "element")
                {
                    level = 2;
                    XmlSchemaElement element = XmlSchemaElement.Read(reader, h);
                    if (element != null)
                    {
                        all.items.Add(element);
                    }
                    continue;
                }
                reader.RaiseInvalidElementError();
            }
            return(all);
        }
 private XmlSchemaParticle CannonicalizeAll(XmlSchemaAll all, bool root)
 {
     if (all.Items.Count > 0)
     {
         XmlSchemaAll to = new XmlSchemaAll {
             MinOccurs = all.MinOccurs,
             MaxOccurs = all.MaxOccurs
         };
         this.CopyPosition(to, all, true);
         for (int i = 0; i < all.Items.Count; i++)
         {
             XmlSchemaParticle item = this.CannonicalizeParticle((XmlSchemaElement) all.Items[i], false);
             if (item != XmlSchemaParticle.Empty)
             {
                 to.Items.Add(item);
             }
         }
         all = to;
     }
     if (all.Items.Count == 0)
     {
         return XmlSchemaParticle.Empty;
     }
     if (!root)
     {
         base.SendValidationEvent("Sch_NotAllAlone", all);
         return XmlSchemaParticle.Empty;
     }
     return all;
 }
예제 #26
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));
        }
예제 #27
0
 private void ProcessAll(XmlSchemaAll all, CodeTypeDeclaration codeType)
 {
     foreach (object item in all.Items)
     {
         if (item.GetType() == typeof(XmlSchemaElement))
         {
             int seqNo = -1;
             ProcessElement((XmlSchemaElement)item, ref seqNo, codeType);
         }
         else if (item.GetType() == typeof(XmlSchemaAnnotation))
         {
             // Ignore for now
             return;
         }
         else
             throw new XmlSchemaException("Invalid particle type: " + item.ToString());
     }
 }
        /// <summary>
        ///     Convert the property into a schema object
        /// </summary>
        public override void GenerateSchemaTypeObjects(PropertyInfo property, XmlSchemaType type, int level)
        {
            Debug.IndentLevel = level;
            Debug.WriteLine("Default {0} {1} {2}", level, property.Name, type.Name);

            var configPropertyAtts = GetAttributes<ConfigurationPropertyAttribute>(property);
            if (configPropertyAtts.Length == 0)
                return;

            var element = new XmlSchemaElement();
            var firstConfigPropertyAttribute = configPropertyAtts[0];

            element.Name = firstConfigPropertyAttribute.Name;
            if (!firstConfigPropertyAttribute.IsRequired)
            {
                element.MinOccurs = 0;
            }

            var ct = new XmlSchemaComplexType();
            element.SchemaType = ct;

            var configCollPropertyAtts = GetAttributes<ConfigurationCollectionAttribute>(property);
            if (configCollPropertyAtts.Length == 0)
                configCollPropertyAtts = GetAttributes<ConfigurationCollectionAttribute>(property.PropertyType);
            if (configCollPropertyAtts.Length == 0)
                return;

            var configCollAttribute = configCollPropertyAtts[0];

            //  we are actually going to add the collection to the parent type by creating
            //  a new group type that consists of a sequence of all the elements that we
            //  expect in the collection

            var name = property.DeclaringType.FullName + "." + property.PropertyType.Name;
            name = name.Replace("+", "_");
            var groupParticle = XmlHelper.CreateGroupType(name);

            XmlSchemaGroupBase seq;
            if (XmlHelper.UseAll && (configCollAttribute.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMap || configCollAttribute.CollectionType == ConfigurationElementCollectionType.AddRemoveClearMapAlternate))
                seq = new XmlSchemaAll();
            else
                seq = new XmlSchemaSequence();
            groupParticle.Particle = seq;

            //  add support for the child elements
            AddCollectionChildren(groupParticle.Particle, configCollAttribute, level);

            //  now add the group to the schema and the parent CT
            if (Generator.Schema.Items.OfType<XmlSchemaGroup>().All(x => x.Name != groupParticle.Name))
                Generator.Schema.Items.Add(groupParticle);

            var parentCt = (XmlSchemaComplexType) type;
            var groupRef = new XmlSchemaGroupRef
            {
                RefName = new XmlQualifiedName(XmlHelper.PrependNamespaceAlias(groupParticle.Name))
            };

            ct.Particle = groupRef;

            var items = ((XmlSchemaGroupBase) parentCt.Particle).Items;

            if (items.OfType<XmlSchemaElement>().All(x => x.Name != element.Name))
                items.Add(element);

            /*            if (items.OfType<XmlSchemaGroupRef>().All(x => x.RefName != groupRef.RefName))
                items.Add(groupRef);*/

            //  add the documentation
            groupRef.AddAnnotation(property, firstConfigPropertyAttribute);
        }
 private bool IsElementFromGroupBase(XmlSchemaElement derivedElement, XmlSchemaGroupBase baseGroupBase)
 {
     if (baseGroupBase is XmlSchemaSequence)
     {
         XmlSchemaSequence derivedGroupBase = new XmlSchemaSequence {
             MinOccurs = 1M,
             MaxOccurs = 1M
         };
         derivedGroupBase.Items.Add(derivedElement);
         if (this.IsGroupBaseFromGroupBase(derivedGroupBase, baseGroupBase, true))
         {
             return true;
         }
         this.restrictionErrorMsg = Res.GetString("Sch_ElementFromGroupBase1", new object[] { 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 choice = new XmlSchemaChoice {
             MinOccurs = 1M,
             MaxOccurs = 1M
         };
         choice.Items.Add(derivedElement);
         if (this.IsGroupBaseFromGroupBase(choice, baseGroupBase, false))
         {
             return true;
         }
         this.restrictionErrorMsg = Res.GetString("Sch_ElementFromGroupBase2", new object[] { 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 all = new XmlSchemaAll {
             MinOccurs = 1M,
             MaxOccurs = 1M
         };
         all.Items.Add(derivedElement);
         if (this.IsGroupBaseFromGroupBase(all, baseGroupBase, true))
         {
             return true;
         }
         this.restrictionErrorMsg = Res.GetString("Sch_ElementFromGroupBase3", new object[] { 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;
 }
		public static XmlSchemaElement CaseSchema()
		{
			var type = new XmlSchemaComplexType();
			XmlSchemaAll allSchema = new XmlSchemaAll();
			type.Particle = allSchema;

			//When
			XmlSchemaComplexType subType = new XmlSchemaComplexType();
			var any = new XmlSchemaAny();
			any.MinOccurs = 1;
			any.MaxOccursString = "unbounded";
			any.ProcessContents = XmlSchemaContentProcessing.Strict;
			any.Namespace = "##local";

			var sequence = new XmlSchemaSequence();
			subType.Particle = sequence;
			sequence.Items.Add(any);

			XmlSchemaElement subElement = new XmlSchemaElement();
			subElement.Name = "when";
			subElement.SchemaType = subType;
			allSchema.Items.Add(subElement);

			//Then
			subType = new XmlSchemaComplexType();
			any = new XmlSchemaAny();
			any.MinOccurs = 1;
			any.MaxOccursString = "unbounded";
			any.ProcessContents = XmlSchemaContentProcessing.Strict;
			any.Namespace = "##local";

			sequence = new XmlSchemaSequence();
			subType.Particle = sequence;
			sequence.Items.Add(any);

			subElement = new XmlSchemaElement();
			subElement.Name = "then";
			subElement.SchemaType = subType;
			allSchema.Items.Add(subElement);

			//Else
			subType = new XmlSchemaComplexType();
			any = new XmlSchemaAny();
			any.MinOccurs = 1;
			any.MaxOccurs = 1;
			any.ProcessContents = XmlSchemaContentProcessing.Strict;
			any.Namespace = "##local";

			sequence = new XmlSchemaSequence();
			subType.Particle = sequence;
			sequence.Items.Add(any);

			subElement = new XmlSchemaElement();
			subElement.Name = "else";
			subElement.SchemaType = subType;
			allSchema.Items.Add(subElement);

			var attrib = new XmlSchemaAttribute();
			attrib.Name = "expressionLanguage";
			attrib.Use = XmlSchemaUse.Optional;
			attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
			type.Attributes.Add(attrib);

			attrib = new XmlSchemaAttribute();
			attrib.Name = "failMessage";
			attrib.Use = XmlSchemaUse.Optional;
			attrib.SchemaTypeName = new XmlQualifiedName("string", "http://www.w3.org/2001/XMLSchema");
			type.Attributes.Add(attrib);

			var element = new XmlSchemaElement();
			element.Name = "case";
			element.SchemaType = type;

			return element;
		}
예제 #31
0
 protected override void Visit(XmlSchemaAll particle)
 {
     // Don't visit children.
 }
예제 #32
0
파일: XmlSchemaAll.cs 프로젝트: nobled/mono
		internal override XmlSchemaParticle GetOptimizedParticle (bool isTop)
		{
			if (OptimizedParticle != null)
				return OptimizedParticle;
			if (Items.Count == 0 || ValidatedMaxOccurs == 0) {
				OptimizedParticle = XmlSchemaParticle.Empty;
				return OptimizedParticle;
			}
			else if (Items.Count == 1) {
				if (ValidatedMinOccurs == 1 && ValidatedMaxOccurs == 1) {
					XmlSchemaSequence seq = new XmlSchemaSequence ();
					this.CopyInfo (seq);
					XmlSchemaParticle p = (XmlSchemaParticle) Items [0];
					p = p.GetOptimizedParticle (false);
					if (p == XmlSchemaParticle.Empty)
						OptimizedParticle = p;
					else {
						seq.Items.Add (p);
						seq.CompiledItems.Add (p);
						seq.Compile (null, schema);
						OptimizedParticle = seq;
					}
					return OptimizedParticle;
				}
			}

			XmlSchemaAll all = new XmlSchemaAll ();
			CopyInfo (all);
			CopyOptimizedItems (all);
			OptimizedParticle = all;
			all.ComputeEmptiable ();

			return OptimizedParticle;
		}
예제 #33
0
        internal static XmlSchemaAll Read(XmlSchemaReader reader, ValidationEventHandler h)
        {
            XmlSchemaAll xmlSchemaAll = new XmlSchemaAll();

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

            while (reader.ReadNextElement())
            {
                if (reader.NodeType == XmlNodeType.EndElement)
                {
                    if (reader.LocalName != "all")
                    {
                        XmlSchemaObject.error(h, "Should not happen :2: XmlSchemaAll.Read, name=" + reader.Name, null);
                    }
                    break;
                }
                if (num <= 1 && reader.LocalName == "annotation")
                {
                    num = 2;
                    XmlSchemaAnnotation xmlSchemaAnnotation = XmlSchemaAnnotation.Read(reader, h);
                    if (xmlSchemaAnnotation != null)
                    {
                        xmlSchemaAll.Annotation = xmlSchemaAnnotation;
                    }
                }
                else if (num <= 2 && reader.LocalName == "element")
                {
                    num = 2;
                    XmlSchemaElement xmlSchemaElement = XmlSchemaElement.Read(reader, h);
                    if (xmlSchemaElement != null)
                    {
                        xmlSchemaAll.items.Add(xmlSchemaElement);
                    }
                }
                else
                {
                    reader.RaiseInvalidElementError();
                }
            }
            return(xmlSchemaAll);
        }
예제 #34
0
파일: XmlSchemaAll.cs 프로젝트: nobled/mono
		//<all
		//  id = ID
		//  maxOccurs = 1 : 1
		//  minOccurs = (0 | 1) : 1
		//  {any attributes with non-schema namespace . . .}>
		//  Content: (annotation?, element*)
		//</all>
		internal static XmlSchemaAll Read(XmlSchemaReader reader, ValidationEventHandler h)
		{
			XmlSchemaAll all = new XmlSchemaAll();
			reader.MoveToElement();

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

			//Read Attributes
			while(reader.MoveToNextAttribute())
			{
				if(reader.Name == "id")
				{
					all.Id = reader.Value;
				}
				else if(reader.Name == "maxOccurs")
				{
					try
					{
						all.MaxOccursString = reader.Value;
					}
					catch(Exception e)
					{
						error(h,reader.Value + " is an invalid value for maxOccurs",e);
					}
				}
				else if(reader.Name == "minOccurs")
				{
					try
					{
						all.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 all",null);
				}
				else
				{
					XmlSchemaUtil.ReadUnhandledAttribute(reader,all);
				}
			}
			
			reader.MoveToElement();
			if(reader.IsEmptyElement)
				return all;

			//Content: (annotation?, element*)
			int level = 1;
			while(reader.ReadNextElement())
			{
				if(reader.NodeType == XmlNodeType.EndElement)
				{
					if(reader.LocalName != xmlname)
						error(h,"Should not happen :2: XmlSchemaAll.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)
						all.Annotation = annotation;
					continue;
				}
				if(level <=2 && reader.LocalName == "element")
				{
					level = 2;
					XmlSchemaElement element = XmlSchemaElement.Read(reader,h);
					if(element != null)
						all.items.Add(element);
					continue;
				}
				reader.RaiseInvalidElementError();
			}
			return all;
		}
예제 #35
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);
        }
예제 #36
0
        private void AddXMLProperties(XmlSchemaElement parent, XmlSchemaObjectCollection items, XmlSchemaObjectCollection attributes, PropertyInfo[] properties)
        {
            foreach (PropertyInfo property in properties)
            {
                if (IsValidProperty(property))
                {
                    string propertyName = property.Name;
                    if (propertyName.Equals("Item") && property.DeclaringType.Name.StartsWith("List`"))
                    {
                        if (!parent.Name.Equals("Items"))
                            propertyName = StringUtils.ToSingular(parent.Name);
                        else
                            propertyName = property.PropertyType.Name;
                    }

                    string xmlPropertyType = GetPropertyTypeName(property.PropertyType, TDataExchangeFormat.Xml);

                    if (property.GetCustomAttributes<XmlAttributeAttribute>().FirstOrDefault() != null)
                    {
                        XmlSchemaAttribute attribute = new XmlSchemaAttribute();
                        attribute.Name = propertyName;
                        attribute.SchemaTypeName = new XmlQualifiedName(xmlPropertyType, XML_NAMESPACE);
                        if (attribute.Name.Equals("type"))
                            attribute.Use = XmlSchemaUse.Optional;
                        attributes.Add(attribute);
                    }
                    else
                    {
                        XmlSchemaElement propertyElement = new XmlSchemaElement();
                        propertyElement.Name = propertyName;

                        if (xmlPropertyType.Equals("array") || xmlPropertyType.Equals("object"))
                        {
                            XmlSchemaComplexType complexType = new XmlSchemaComplexType();
                            propertyElement.SchemaType = complexType;

                            XmlSchemaGroupBase sequence = null;
                            if (xmlPropertyType.Equals("array"))
                            {
                                sequence = new XmlSchemaSequence();
                                sequence.MinOccursString = "0";
                                sequence.MaxOccursString = "unbounded";

                                if (parent != null)
                                {
                                    // nested empty collections shouldn't have to exist.
                                    propertyElement.UnhandledAttributes = new XmlAttribute[1];
                                    propertyElement.UnhandledAttributes[0] = new XmlDocument().CreateAttribute("minOccurs");
                                    propertyElement.UnhandledAttributes[0].Value = "0";
                                }
                            }
                            else
                            {
                                sequence = new XmlSchemaAll();
                            }

                            AddXMLProperties(propertyElement, sequence.Items, complexType.Attributes, property.PropertyType.GetProperties());

                            if (sequence.Items.Count > 0)
                            {
                                complexType.Particle = sequence;
                            }
                        }
                        else
                        {
                            propertyElement.SchemaTypeName = new XmlQualifiedName(xmlPropertyType, XML_NAMESPACE);
                        }
                        items.Add(propertyElement);
                    }
                }
            }
        }
        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);
        }
예제 #38
0
파일: XSD2Class.cs 프로젝트: nobled/mono
		private void GenerateParticleAllField (XmlSchemaAll xsall)
		{
			foreach (XmlSchemaParticle cp in xsall.Items)
				GenerateParticleField (cp);
		}
 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;
 }
예제 #40
0
		private XmlSchemaParticle GenerateSchemaElementsForMembers(IXmlTypeSerialiser typeSerialiser)
		{
			XmlSchemaAll group = new XmlSchemaAll();
			foreach (IXmlMemberSerialiser memberSerialiser in typeSerialiser.MemberSerialisers)
			{
                var item = new XmlSchemaElement
                {
                    MaxOccurs = 1,
                    MinOccurs = memberSerialiser.Attribute.Required ? 1 : 0
                };
                AddDocumentation(memberSerialiser.Attribute.Description, item);
				item.Name = memberSerialiser.Attribute.Name;
                GenerateElementType(memberSerialiser.ReflectorMember.MemberType, item, memberSerialiser.Attribute.HasCustomFactory);
				group.Items.Add(item);				
			}
			return group;
		}
예제 #41
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;
     }
 }
예제 #42
0
		public virtual void Check (ConformanceCheckContext ctx, XmlSchemaAll value) {}
예제 #43
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);
        }
예제 #44
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);
        }
 void Write43_XmlSchemaAll(XmlSchemaAll o) {
     if ((object)o == null) return;
     WriteStartElement("all");
     
     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();
 }
 private XmlSchemaParticle CannonicalizeAll(XmlSchemaAll all, bool root, bool substitution) {
     if (all.Items.Count > 0) {
         XmlSchemaAll newAll = new XmlSchemaAll();
         newAll.MinOccurs = all.MinOccurs;
         newAll.MaxOccurs = all.MaxOccurs;
         newAll.SourceUri = all.SourceUri; // all is the only one that might need and error message
         newAll.LineNumber = all.LineNumber;
         newAll.LinePosition = all.LinePosition;
         for (int i = 0; i < all.Items.Count; ++i) {
             XmlSchemaParticle p = CannonicalizeParticle((XmlSchemaElement)all.Items[i], false, substitution);
             if (p != XmlSchemaParticle.Empty) {
                 newAll.Items.Add(p);
             }
         }
         all = newAll;
     }
     if (all.Items.Count == 0) {
         return XmlSchemaParticle.Empty;
     }
     else if (root && all.Items.Count == 1) {
         XmlSchemaSequence newSequence = new XmlSchemaSequence();
         newSequence.MinOccurs = all.MinOccurs;
         newSequence.MaxOccurs = all.MaxOccurs;
         newSequence.Items.Add((XmlSchemaParticle)all.Items[0]);
         return newSequence;
     }
     else if (!root && all.Items.Count == 1 && all.MinOccurs == decimal.One && all.MaxOccurs == decimal.One) {
         return (XmlSchemaParticle)all.Items[0];
     }
     else if (!root) {
         SendValidationEvent(Res.Sch_NotAllAlone, all);
         return XmlSchemaParticle.Empty;
     }
     else {
         return all;
     }
 }
 private bool IsSequenceFromAll(XmlSchemaSequence derivedSequence, XmlSchemaAll baseAll)
 {
     if (!this.IsValidOccurrenceRangeRestriction(derivedSequence, baseAll) || (derivedSequence.Items.Count > baseAll.Items.Count))
     {
         return false;
     }
     BitSet set = new BitSet(baseAll.Items.Count);
     for (int i = 0; i < derivedSequence.Items.Count; i++)
     {
         int mappingParticle = this.GetMappingParticle((XmlSchemaParticle) derivedSequence.Items[i], baseAll.Items);
         if (mappingParticle < 0)
         {
             return false;
         }
         if (set[mappingParticle])
         {
             return false;
         }
         set.Set(mappingParticle);
     }
     for (int j = 0; j < baseAll.Items.Count; j++)
     {
         if (!set[j] && !this.IsParticleEmptiable((XmlSchemaParticle) baseAll.Items[j]))
         {
             return false;
         }
     }
     return true;
 }
예제 #48
0
		public XsdAllValidationState (XmlSchemaAll all, XsdParticleStateManager manager)
			: base (manager)
		{
			this.all = all;
		}