internal XmlSchemaObjectCollection Clone() { XmlSchemaObjectCollection objects = new XmlSchemaObjectCollection(); objects.Add(this); return(objects); }
internal XmlSchemaObjectCollection Clone() { XmlSchemaObjectCollection coll = new XmlSchemaObjectCollection(); coll.Add(this); return(coll); }
void AddExternalComponentsTo(XmlSchema s, XmlSchemaObjectCollection items, ValidationEventHandler handler, List <CompiledSchemaMemo> handledUris, XmlResolver resolver, XmlSchemaSet col) { foreach (XmlSchemaExternal ext in s.Includes) { s.ProcessExternal(handler, handledUris, resolver, ext, col); } foreach (XmlSchemaObject obj in s.compilationItems) { items.Add(obj); } // Items might be already resolved (recursive schema imports), or might not be (other cases), so we add items only when appropriate here. (duplicate check is anyways done elsewhere) foreach (XmlSchemaObject obj in s.Items) { if (!items.Contains(obj)) { items.Add(obj); } } }
void AddExternalComponentsTo(XmlSchema s, XmlSchemaObjectCollection items, ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver, XmlSchemaSet col) { foreach (XmlSchemaExternal ext in s.Includes) { ProcessExternal(handler, handledUris, resolver, ext, col); } // if (ext.Schema != null) // AddExternalComponentsTo (ext.Schema, items); foreach (XmlSchemaObject obj in s.Items) { items.Add(obj); } }
void AddExternalComponentsTo(XmlSchema s, XmlSchemaObjectCollection items) { foreach (XmlSchemaExternal ext in s.Includes) { if (ext.Schema != null) { AddExternalComponentsTo(ext.Schema, items); } } foreach (XmlSchemaObject obj in s.Items) { items.Add(obj); } }
private XmlSchemaElement AddElement(string localName, string prefix, string childURI, XmlSchema parentSchema, XmlSchemaObjectCollection addLocation, int positionWithinCollection) { if (childURI == "http://www.w3.org/2001/XMLSchema") { throw new XmlSchemaInferenceException("SchInf_schema", 0, 0); } XmlSchemaElement item = null; XmlSchemaElement element2 = item; XmlSchema schema = null; bool bCreatingNewType = true; if (childURI == string.Empty) { childURI = null; } if ((parentSchema != null) && (childURI == parentSchema.TargetNamespace)) { item = new XmlSchemaElement { Name = localName }; schema = parentSchema; if ((schema.ElementFormDefault != XmlSchemaForm.Qualified) && (addLocation != null)) { item.Form = XmlSchemaForm.Qualified; } } else if (this.schemaSet.Contains(childURI)) { item = this.FindGlobalElement(childURI, localName, out schema); if (item == null) { ArrayList list = this.schemaSet.Schemas(childURI) as ArrayList; if ((list != null) && (list.Count > 0)) { schema = list[0] as XmlSchema; } item = new XmlSchemaElement { Name = localName }; schema.Items.Add(item); } else { bCreatingNewType = false; } } else { schema = this.CreateXmlSchema(childURI); if (prefix.Length != 0) { this.NamespaceManager.AddNamespace(prefix, childURI); } item = new XmlSchemaElement { Name = localName }; schema.Items.Add(item); } if (parentSchema == null) { parentSchema = schema; this.rootSchema = parentSchema; } if (childURI != parentSchema.TargetNamespace) { bool flag2 = true; for (int i = 0; i < parentSchema.Includes.Count; i++) { XmlSchemaImport import = parentSchema.Includes[i] as XmlSchemaImport; if ((import != null) && (import.Namespace == childURI)) { flag2 = false; } } if (flag2) { XmlSchemaImport import2 = new XmlSchemaImport { Schema = schema, Namespace = childURI }; parentSchema.Includes.Add(import2); } } element2 = item; if (addLocation != null) { if (childURI == parentSchema.TargetNamespace) { if (this.Occurrence == InferenceOption.Relaxed) { item.MinOccurs = 0M; } if (positionWithinCollection == -1) { positionWithinCollection = addLocation.Add(item); } else { addLocation.Insert(positionWithinCollection, item); } } else { XmlSchemaElement element3 = new XmlSchemaElement { RefName = new XmlQualifiedName(localName, childURI) }; if (this.Occurrence == InferenceOption.Relaxed) { element3.MinOccurs = 0M; } if (positionWithinCollection == -1) { positionWithinCollection = addLocation.Add(element3); } else { addLocation.Insert(positionWithinCollection, element3); } element2 = element3; } } this.InferElement(item, bCreatingNewType, schema); return element2; }
internal XmlSchemaObjectCollection Clone() { XmlSchemaObjectCollection coll = new XmlSchemaObjectCollection(); coll.Add(this); return coll; }
internal void ProcessAttributes(ref XmlSchemaElement xse, XmlSchemaType effectiveSchemaType, bool bCreatingNewType, XmlSchema parentSchema) { XmlSchemaObjectCollection attributesSeen = new XmlSchemaObjectCollection(); XmlSchemaComplexType ct = effectiveSchemaType as XmlSchemaComplexType; Debug.Assert(xtr.NodeType == XmlNodeType.Attribute); do { if (xtr.NamespaceURI == XmlSchema.Namespace) { throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0); } if (xtr.NamespaceURI == XmlReservedNs.NsXmlNs) { if (xtr.Prefix=="xmlns") NamespaceManager.AddNamespace(xtr.LocalName, xtr.Value); } else if (xtr.NamespaceURI == XmlReservedNs.NsXsi) { string localName = xtr.LocalName; if (localName == "nil") { xse.IsNillable = true; } else if (localName != "type" && localName != "schemaLocation" && localName != "noNamespaceSchemaLocation") { throw new XmlSchemaInferenceException(Res.Sch_NotXsiAttribute,localName); } } else { if (ct == null || ct == XmlSchemaComplexType.AnyType) { ct = new XmlSchemaComplexType(); xse.SchemaType = ct; } XmlSchemaAttribute xsa=null; //The earlier assumption of checking just schemaTypeName !Empty is not correct for schemas that are not generated by us, schemaTypeName can point to any complex type as well //Check that it is a simple type by checking typeCode //Switch to complex type simple content extension if (effectiveSchemaType != null && effectiveSchemaType.Datatype != null && !xse.SchemaTypeName.IsEmpty) { //type was previously simple type, now it will become complex with simple type extension Debug.Assert(ct != null); XmlSchemaSimpleContent sc = new XmlSchemaSimpleContent(); ct.ContentModel = sc; XmlSchemaSimpleContentExtension sce = new XmlSchemaSimpleContentExtension(); sc.Content = sce; sce.BaseTypeName = xse.SchemaTypeName; sce.LineNumber = xse.LineNumber; xse.LineNumber = 0; xse.SchemaTypeName = XmlQualifiedName.Empty; //re-set the name } Debug.Assert(ct != null); //either the user-defined type itself is a complex type or we switched from a simple type to a complex type if (ct.ContentModel != null) { XmlSchemaSimpleContentExtension sce = CheckSimpleContentExtension(ct); Debug.Assert(sce != null); xsa = AddAttribute(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, xtr.Value, bCreatingNewType, parentSchema, sce.Attributes, ct.AttributeUses); } else //add atributes directly to complex type { xsa = AddAttribute(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, xtr.Value, bCreatingNewType, parentSchema, ct.Attributes, ct.AttributeUses); } if (xsa != null) { attributesSeen.Add(xsa); } } } while (xtr.MoveToNextAttribute()); if (!bCreatingNewType) { //make attributes that did not appear this time optional if (ct!=null) { MakeExistingAttributesOptional(ct, attributesSeen); } } }
void DoCompile (ValidationEventHandler handler, Hashtable handledUris, XmlSchemaSet col, XmlResolver resolver) { SetParent (); CompilationId = col.CompilationId; schemas = col; if (!schemas.Contains (this)) // e.g. xs:import schemas.Add (this); attributeGroups.Clear (); attributes.Clear (); elements.Clear (); groups.Clear (); notations.Clear (); schemaTypes.Clear (); //1. Union and List are not allowed in block default if (BlockDefault != XmlSchemaDerivationMethod.All) { if((BlockDefault & XmlSchemaDerivationMethod.List)!=0 ) error(handler, "list is not allowed in blockDefault attribute"); if((BlockDefault & XmlSchemaDerivationMethod.Union)!=0 ) error(handler, "union is not allowed in blockDefault attribute"); } //2. Substitution is not allowed in finaldefault. if (FinalDefault != XmlSchemaDerivationMethod.All) { if((FinalDefault & XmlSchemaDerivationMethod.Substitution)!=0 ) error(handler, "substitution is not allowed in finalDefault attribute"); } //3. id must be of type ID XmlSchemaUtil.CompileID(Id, this, col.IDCollection, handler); //4. targetNamespace should be of type anyURI or absent if (TargetNamespace != null) { if (TargetNamespace.Length == 0) error (handler, "The targetNamespace attribute cannot have have empty string as its value."); if(!XmlSchemaUtil.CheckAnyUri (TargetNamespace)) error(handler, TargetNamespace+" is not a valid value for targetNamespace attribute of schema"); } //5. version should be of type normalizedString if (!XmlSchemaUtil.CheckNormalizedString(Version)) error(handler, Version + "is not a valid value for version attribute of schema"); // Compile the content of this schema compilationItems = new XmlSchemaObjectCollection (); for (int i = 0; i < Items.Count; i++) { compilationItems.Add (Items [i]); } // First, we run into inclusion schemas to collect // compilation target items into compiledItems. for (int i = 0; i < Includes.Count; i++) ProcessExternal (handler, handledUris, resolver, Includes [i] as XmlSchemaExternal, col); // Compilation phase. // At least each Compile() must give unique (qualified) name for each component. // It also checks self-resolvable properties correctness. // Post compilation schema information contribution is not done here. // It should be done by Validate(). for (int i = 0; i < compilationItems.Count; i++) { XmlSchemaObject obj = compilationItems [i]; if(obj is XmlSchemaAnnotation) { int numerr = ((XmlSchemaAnnotation)obj).Compile (handler, this); errorCount += numerr; } else if (obj is XmlSchemaAttribute) { XmlSchemaAttribute attr = (XmlSchemaAttribute) obj; int numerr = attr.Compile (handler, this); errorCount += numerr; if(numerr == 0) { XmlSchemaUtil.AddToTable (Attributes, attr, attr.QualifiedName, handler); } } else if (obj is XmlSchemaAttributeGroup) { XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup) obj; int numerr = attrgrp.Compile(handler, this); errorCount += numerr; if (numerr == 0) XmlSchemaUtil.AddToTable ( AttributeGroups, attrgrp, attrgrp.QualifiedName, handler); } else if (obj is XmlSchemaComplexType) { XmlSchemaComplexType ctype = (XmlSchemaComplexType) obj; int numerr = ctype.Compile (handler, this); errorCount += numerr; if (numerr == 0) XmlSchemaUtil.AddToTable ( schemaTypes, ctype, ctype.QualifiedName, handler); } else if (obj is XmlSchemaSimpleType) { XmlSchemaSimpleType stype = (XmlSchemaSimpleType) obj; stype.islocal = false; //This simple type is toplevel int numerr = stype.Compile (handler, this); errorCount += numerr; if (numerr == 0) XmlSchemaUtil.AddToTable ( SchemaTypes, stype, stype.QualifiedName, handler); } else if (obj is XmlSchemaElement) { XmlSchemaElement elem = (XmlSchemaElement) obj; elem.parentIsSchema = true; int numerr = elem.Compile (handler, this); errorCount += numerr; if (numerr == 0) XmlSchemaUtil.AddToTable ( Elements, elem, elem.QualifiedName, handler); } else if (obj is XmlSchemaGroup) { XmlSchemaGroup grp = (XmlSchemaGroup) obj; int numerr = grp.Compile (handler, this); errorCount += numerr; if (numerr == 0) XmlSchemaUtil.AddToTable ( Groups, grp, grp.QualifiedName, handler); } else if (obj is XmlSchemaNotation) { XmlSchemaNotation ntn = (XmlSchemaNotation) obj; int numerr = ntn.Compile (handler, this); errorCount += numerr; if (numerr == 0) XmlSchemaUtil.AddToTable ( Notations, ntn, ntn.QualifiedName, handler); } else { ValidationHandler.RaiseValidationEvent ( handler, null, String.Format ("Object of Type {0} is not valid in Item Property of Schema", obj.GetType ().Name), null, this, null, XmlSeverityType.Error); } } }
// Attributes might be redefined, so there is an existing attribute for the same name, skip it. // FIXME: this is nothing more than just a hack. // Basically it should use // XmlSchemaComplexType.AttributeUses. XmlSchemaObjectCollection CollectAttributeUsesNonOverlap ( XmlSchemaObjectCollection src, ClassMap map) { XmlSchemaObjectCollection atts = new XmlSchemaObjectCollection (); foreach (XmlSchemaAttribute a in src) if (map.GetAttribute (a.QualifiedName.Name, a.QualifiedName.Namespace) == null) atts.Add (a); return atts; }
void DoCompile(ValidationEventHandler handler, List <CompiledSchemaMemo> handledUris, XmlSchemaSet col, XmlResolver resolver) { SetParent(); CompilationId = col.CompilationId; schemas = col; if (!schemas.Contains(this)) // e.g. xs:import { schemas.Add(this); } attributeGroups.Clear(); attributes.Clear(); elements.Clear(); groups.Clear(); notations.Clear(); schemaTypes.Clear(); named_identities.Clear(); ids.Clear(); compilationItems.Clear(); //1. Union and List are not allowed in block default if (BlockDefault != XmlSchemaDerivationMethod.All) { if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0) { error(handler, "list is not allowed in blockDefault attribute"); } if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0) { error(handler, "union is not allowed in blockDefault attribute"); } } //2. Substitution is not allowed in finaldefault. if (FinalDefault != XmlSchemaDerivationMethod.All) { if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0) { error(handler, "substitution is not allowed in finalDefault attribute"); } } //3. id must be of type ID XmlSchemaUtil.CompileID(Id, this, IDCollection, handler); //4. targetNamespace should be of type anyURI or absent if (TargetNamespace != null) { if (TargetNamespace.Length == 0) { error(handler, "The targetNamespace attribute cannot have have empty string as its value."); } if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace)) { error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema"); } } //5. version should be of type normalizedString if (!XmlSchemaUtil.CheckNormalizedString(Version)) { error(handler, Version + "is not a valid value for version attribute of schema"); } // Compile the content of this schema for (int i = 0; i < Items.Count; i++) { compilationItems.Add(Items [i]); } // First, we run into inclusion schemas to collect // compilation target items into compiledItems. for (int i = 0; i < Includes.Count; i++) { ProcessExternal(handler, handledUris, resolver, Includes [i] as XmlSchemaExternal, col); } // Compilation phase. // At least each Compile() must give unique (qualified) name for each component. // It also checks self-resolvable properties correctness. // Post compilation schema information contribution is not done here. // It should be done by Validate(). for (int i = 0; i < compilationItems.Count; i++) { XmlSchemaObject obj = compilationItems [i]; if (obj is XmlSchemaAnnotation) { int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this); errorCount += numerr; } else if (obj is XmlSchemaAttribute) { XmlSchemaAttribute attr = (XmlSchemaAttribute)obj; int numerr = attr.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler); } } else if (obj is XmlSchemaAttributeGroup) { XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj; int numerr = attrgrp.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( AttributeGroups, attrgrp, attrgrp.QualifiedName, handler); } } else if (obj is XmlSchemaComplexType) { XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj; int numerr = ctype.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( schemaTypes, ctype, ctype.QualifiedName, handler); } } else if (obj is XmlSchemaSimpleType) { XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj; stype.islocal = false; //This simple type is toplevel int numerr = stype.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( SchemaTypes, stype, stype.QualifiedName, handler); } } else if (obj is XmlSchemaElement) { XmlSchemaElement elem = (XmlSchemaElement)obj; elem.parentIsSchema = true; int numerr = elem.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Elements, elem, elem.QualifiedName, handler); } } else if (obj is XmlSchemaGroup) { XmlSchemaGroup grp = (XmlSchemaGroup)obj; int numerr = grp.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Groups, grp, grp.QualifiedName, handler); } } else if (obj is XmlSchemaNotation) { XmlSchemaNotation ntn = (XmlSchemaNotation)obj; int numerr = ntn.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Notations, ntn, ntn.QualifiedName, handler); } } else { ValidationHandler.RaiseValidationEvent( handler, null, String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name), null, this, null, XmlSeverityType.Error); } } }
private void InferAttributes(Element el, string ns, bool isNew) { // Now this element is going to have complexType. // It currently not, then we have to replace it. ComplexType ct = null; SOMList attList = null; Hashtable table = null; do { switch (source.NamespaceURI) { case NamespaceXml: if (schemas.Schemas( NamespaceXml).Count == 0) { IncludeXmlAttributes(); } break; case XmlSchema.InstanceNamespace: if (source.LocalName == "nil") { el.IsNillable = true; } // all other xsi:* atts are ignored continue; case NamespaceXmlns: continue; } if (ct == null) { ct = ToComplexType(el); attList = GetAttributes(ct); table = CollectAttrTable(attList); } QName attrName = new QName( source.LocalName, source.NamespaceURI); Attr attr = table [attrName] as Attr; if (attr == null) { attList.Add(InferNewAttribute( attrName, isNew, ns)); } else { table.Remove(attrName); if (attr.RefName != null && attr.RefName != QName.Empty) { continue; // just a reference } InferMergedAttribute(attr); } } while (source.MoveToNextAttribute()); // mark all attr definitions that did not appear // as optional. if (table != null) { foreach (Attr attr in table.Values) { attr.Use = Use.Optional; } } }
private void AddReferenceAttributes(XmlSchemaObjectCollection attributes, XmlSchema schema) { SchemaHelper.AddSchemaImport("http://schemas.microsoft.com/2003/10/Serialization/", schema); schema.Namespaces.Add("ser", "http://schemas.microsoft.com/2003/10/Serialization/"); attributes.Add(IdAttribute); attributes.Add(RefAttribute); }
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); } } } }
void AddExternalComponentsTo (XmlSchema s, XmlSchemaObjectCollection items, ValidationEventHandler handler, List<CompiledSchemaMemo> handledUris, XmlResolver resolver, XmlSchemaSet col) { foreach (XmlSchemaExternal ext in s.Includes) s.ProcessExternal (handler, handledUris, resolver, ext, col); foreach (XmlSchemaObject obj in s.compilationItems) items.Add (obj); // Items might be already resolved (recursive schema imports), or might not be (other cases), so we add items only when appropriate here. (duplicate check is anyways done elsewhere) foreach (XmlSchemaObject obj in s.Items) if (!items.Contains (obj)) items.Add (obj); }
void AddReferenceAttributes(XmlSchemaObjectCollection attributes, XmlSchema schema) { SchemaHelper.AddSchemaImport(Globals.SerializationNamespace, schema); schema.Namespaces.Add(Globals.SerPrefixForSchema, Globals.SerializationNamespace); attributes.Add(IdAttribute); attributes.Add(RefAttribute); }
void addCollection(XmlSchemaObjectCollection coll, XmlSchemaObject obj, TreeNode node, ObjectType imgIdx) { coll.Add(obj); node.Tag = obj; node.ImageIndex = (int)imgIdx; node.SelectedImageIndex = (int)imgIdx; CompileSchema(); }
private XmlSchemaAttribute AddAttribute(string localName, string prefix, string childURI, string attrValue, bool bCreatingNewType, XmlSchema parentSchema, XmlSchemaObjectCollection addLocation, XmlSchemaObjectTable compiledAttributes) { ICollection values; ICollection is3; if (childURI == "http://www.w3.org/2001/XMLSchema") { throw new XmlSchemaInferenceException("SchInf_schema", 0, 0); } XmlSchemaAttribute item = null; int iTypeFlags = -1; XmlSchemaAttribute attribute2 = null; XmlSchema schema = null; bool flag = true; if (compiledAttributes.Count > 0) { values = compiledAttributes.Values; is3 = addLocation; } else { values = addLocation; is3 = null; } if (childURI == "http://www.w3.org/XML/1998/namespace") { XmlSchemaAttribute attribute3 = null; attribute3 = this.FindAttributeRef(values, localName, childURI); if ((attribute3 == null) && (is3 != null)) { attribute3 = this.FindAttributeRef(is3, localName, childURI); } if (attribute3 == null) { attribute3 = new XmlSchemaAttribute { RefName = new XmlQualifiedName(localName, childURI) }; if (bCreatingNewType && (this.Occurrence == InferenceOption.Restricted)) { attribute3.Use = XmlSchemaUse.Required; } else { attribute3.Use = XmlSchemaUse.Optional; } addLocation.Add(attribute3); } attribute2 = attribute3; } else { if (childURI.Length == 0) { schema = parentSchema; flag = false; } else if ((childURI != null) && !this.schemaSet.Contains(childURI)) { schema = new XmlSchema { AttributeFormDefault = XmlSchemaForm.Unqualified, ElementFormDefault = XmlSchemaForm.Qualified }; if (childURI.Length != 0) { schema.TargetNamespace = childURI; } this.schemaSet.Add(schema); if ((prefix.Length != 0) && (string.Compare(prefix, "xml", StringComparison.OrdinalIgnoreCase) != 0)) { this.NamespaceManager.AddNamespace(prefix, childURI); } } else { ArrayList list = this.schemaSet.Schemas(childURI) as ArrayList; if ((list != null) && (list.Count > 0)) { schema = list[0] as XmlSchema; } } if (childURI.Length != 0) { XmlSchemaAttribute attribute4 = null; attribute4 = this.FindAttributeRef(values, localName, childURI); if ((attribute4 == null) & (is3 != null)) { attribute4 = this.FindAttributeRef(is3, localName, childURI); } if (attribute4 == null) { attribute4 = new XmlSchemaAttribute { RefName = new XmlQualifiedName(localName, childURI) }; if (bCreatingNewType && (this.Occurrence == InferenceOption.Restricted)) { attribute4.Use = XmlSchemaUse.Required; } else { attribute4.Use = XmlSchemaUse.Optional; } addLocation.Add(attribute4); } attribute2 = attribute4; item = this.FindAttribute(schema.Items, localName); if (item == null) { item = new XmlSchemaAttribute { Name = localName, SchemaTypeName = this.RefineSimpleType(attrValue, ref iTypeFlags), LineNumber = iTypeFlags }; schema.Items.Add(item); } else { if (item.Parent == null) { iTypeFlags = item.LineNumber; } else { iTypeFlags = GetSchemaType(item.SchemaTypeName); item.Parent = null; } item.SchemaTypeName = this.RefineSimpleType(attrValue, ref iTypeFlags); item.LineNumber = iTypeFlags; } } else { item = this.FindAttribute(values, localName); if ((item == null) && (is3 != null)) { item = this.FindAttribute(is3, localName); } if (item == null) { item = new XmlSchemaAttribute { Name = localName, SchemaTypeName = this.RefineSimpleType(attrValue, ref iTypeFlags), LineNumber = iTypeFlags }; if (bCreatingNewType && (this.Occurrence == InferenceOption.Restricted)) { item.Use = XmlSchemaUse.Required; } else { item.Use = XmlSchemaUse.Optional; } addLocation.Add(item); if (schema.AttributeFormDefault != XmlSchemaForm.Unqualified) { item.Form = XmlSchemaForm.Unqualified; } } else { if (item.Parent == null) { iTypeFlags = item.LineNumber; } else { iTypeFlags = GetSchemaType(item.SchemaTypeName); item.Parent = null; } item.SchemaTypeName = this.RefineSimpleType(attrValue, ref iTypeFlags); item.LineNumber = iTypeFlags; } attribute2 = item; } } string str = null; if (flag && (childURI != parentSchema.TargetNamespace)) { for (int i = 0; i < parentSchema.Includes.Count; i++) { XmlSchemaImport import = parentSchema.Includes[i] as XmlSchemaImport; if ((import != null) && (import.Namespace == childURI)) { flag = false; } } if (!flag) { return attribute2; } XmlSchemaImport import2 = new XmlSchemaImport { Schema = schema }; if (childURI.Length != 0) { str = childURI; } import2.Namespace = str; parentSchema.Includes.Add(import2); } return attribute2; }
internal XmlSchemaElement FindMatchingElement(bool bCreatingNewType, XmlReader xtr, XmlSchemaComplexType ct, ref int lastUsedSeqItem, ref bool bParticleChanged, XmlSchema parentSchema, bool setMaxoccurs) { int num6; if (xtr.NamespaceURI == "http://www.w3.org/2001/XMLSchema") { throw new XmlSchemaInferenceException("SchInf_schema", 0, 0); } bool flag = lastUsedSeqItem == -1; XmlSchemaObjectCollection objects = new XmlSchemaObjectCollection(); if (!(ct.Particle.GetType() == typeof(XmlSchemaSequence))) { throw new XmlSchemaInferenceException("SchInf_noseq", 0, 0); } string namespaceURI = xtr.NamespaceURI; if (namespaceURI.Length == 0) { namespaceURI = null; } XmlSchemaSequence sequence = (XmlSchemaSequence) ct.Particle; if ((sequence.Items.Count < 1) && !bCreatingNewType) { lastUsedSeqItem = 0; XmlSchemaElement element = this.AddElement(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, parentSchema, sequence.Items, -1); element.MinOccurs = 0M; return element; } if (sequence.Items[0].GetType() == typeof(XmlSchemaChoice)) { XmlSchemaChoice choice = (XmlSchemaChoice) sequence.Items[0]; for (int i = 0; i < choice.Items.Count; i++) { XmlSchemaElement element2 = choice.Items[i] as XmlSchemaElement; if (element2 == null) { throw new XmlSchemaInferenceException("SchInf_UnknownParticle", 0, 0); } if ((element2.Name == xtr.LocalName) && (parentSchema.TargetNamespace == namespaceURI)) { this.InferElement(element2, false, parentSchema); this.SetMinMaxOccurs(element2, setMaxoccurs); return element2; } if ((element2.RefName.Name == xtr.LocalName) && (element2.RefName.Namespace == xtr.NamespaceURI)) { XmlSchemaElement element3 = this.FindGlobalElement(namespaceURI, xtr.LocalName, out parentSchema); this.InferElement(element3, false, parentSchema); this.SetMinMaxOccurs(element2, setMaxoccurs); return element3; } } return this.AddElement(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, parentSchema, choice.Items, -1); } int num2 = 0; if (lastUsedSeqItem >= 0) { num2 = lastUsedSeqItem; } XmlSchemaParticle particle = sequence.Items[num2] as XmlSchemaParticle; XmlSchemaElement xse = particle as XmlSchemaElement; if (xse == null) { throw new XmlSchemaInferenceException("SchInf_UnknownParticle", 0, 0); } if ((xse.Name == xtr.LocalName) && (parentSchema.TargetNamespace == namespaceURI)) { if (!flag) { xse.MaxOccurs = 79228162514264337593543950335M; } lastUsedSeqItem = num2; this.InferElement(xse, false, parentSchema); this.SetMinMaxOccurs(xse, false); return xse; } if ((xse.RefName.Name == xtr.LocalName) && (xse.RefName.Namespace == xtr.NamespaceURI)) { if (!flag) { xse.MaxOccurs = 79228162514264337593543950335M; } lastUsedSeqItem = num2; XmlSchemaElement element6 = this.FindGlobalElement(namespaceURI, xtr.LocalName, out parentSchema); this.InferElement(element6, false, parentSchema); this.SetMinMaxOccurs(xse, false); return xse; } if (flag && (xse.MinOccurs != 0M)) { objects.Add(xse); } num2++; while (num2 < sequence.Items.Count) { particle = sequence.Items[num2] as XmlSchemaParticle; xse = particle as XmlSchemaElement; if (xse == null) { throw new XmlSchemaInferenceException("SchInf_UnknownParticle", 0, 0); } if ((xse.Name == xtr.LocalName) && (parentSchema.TargetNamespace == namespaceURI)) { lastUsedSeqItem = num2; for (int j = 0; j < objects.Count; j++) { ((XmlSchemaElement) objects[j]).MinOccurs = 0M; } this.InferElement(xse, false, parentSchema); this.SetMinMaxOccurs(xse, setMaxoccurs); return xse; } if ((xse.RefName.Name == xtr.LocalName) && (xse.RefName.Namespace == xtr.NamespaceURI)) { lastUsedSeqItem = num2; for (int k = 0; k < objects.Count; k++) { ((XmlSchemaElement) objects[k]).MinOccurs = 0M; } XmlSchemaElement element7 = this.FindGlobalElement(namespaceURI, xtr.LocalName, out parentSchema); this.InferElement(element7, false, parentSchema); this.SetMinMaxOccurs(xse, setMaxoccurs); return element7; } objects.Add(xse); num2++; } XmlSchemaElement el = null; XmlSchemaElement element9 = null; if (parentSchema.TargetNamespace == namespaceURI) { el = this.FindElement(sequence.Items, xtr.LocalName); element9 = el; } else { el = this.FindElementRef(sequence.Items, xtr.LocalName, xtr.NamespaceURI); if (el != null) { element9 = this.FindGlobalElement(namespaceURI, xtr.LocalName, out parentSchema); } } if (el != null) { XmlSchemaChoice item = new XmlSchemaChoice { MaxOccurs = 79228162514264337593543950335M }; this.SetMinMaxOccurs(el, setMaxoccurs); this.InferElement(element9, false, parentSchema); for (int m = 0; m < sequence.Items.Count; m++) { item.Items.Add(this.CreateNewElementforChoice((XmlSchemaElement) sequence.Items[m])); } sequence.Items.Clear(); sequence.Items.Add(item); return el; } lastUsedSeqItem = num6 = lastUsedSeqItem + 1; el = this.AddElement(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, parentSchema, sequence.Items, num6); if (!bCreatingNewType) { el.MinOccurs = 0M; } return el; }
internal XmlSchemaObjectCollection GetParticleItems(XmlSchemaParticle pt){ if (pt is XmlSchemaSequence) return ((XmlSchemaSequence)pt).Items; if (pt is XmlSchemaAll) return ((XmlSchemaAll)pt).Items; if (pt is XmlSchemaChoice) return ((XmlSchemaChoice)pt).Items; if (pt is XmlSchemaAny) return null; // the code below is a little hack for the SOM behavior if (pt is XmlSchemaElement) { XmlSchemaObjectCollection Items = new XmlSchemaObjectCollection(); Items.Add(pt); return Items; } if (pt is XmlSchemaGroupRef) return GetParticleItems( ((XmlSchemaGroupRef)pt).Particle ); // should never get here. return null; }
private XmlSchemaAttribute AddAttribute(string localName, string prefix, string childURI, string attrValue, bool bCreatingNewType, XmlSchema parentSchema, XmlSchemaObjectCollection addLocation, XmlSchemaObjectTable compiledAttributes) { if (childURI == XmlSchema.Namespace) { throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0); } XmlSchemaAttribute xsa = null; int AttributeType = -1; XmlSchemaAttribute returnedAttribute = null; //this value will change to attributeReference if childURI!= parentURI XmlSchema xs = null; bool add = true; Debug.Assert(compiledAttributes != null); //AttributeUses is never null ICollection searchCollection; if (compiledAttributes.Count > 0) { searchCollection = compiledAttributes.Values; } else { searchCollection = addLocation; } if (childURI == "http://www.w3.org/XML/1998/namespace") { XmlSchemaAttribute attributeReference = null; //see if the reference exists attributeReference = FindAttributeRef(searchCollection, localName, childURI); if (attributeReference == null) { attributeReference = new XmlSchemaAttribute(); attributeReference.RefName = new XmlQualifiedName(localName, childURI); if (bCreatingNewType && this.Occurrence == InferenceOption.Restricted) { attributeReference.Use = XmlSchemaUse.Required; } else { attributeReference.Use = XmlSchemaUse.Optional; } addLocation.Add(attributeReference); } returnedAttribute = attributeReference; } else { if (childURI.Length == 0) { xs = parentSchema; add = false; } else if (childURI != null && !schemaSet.Contains(childURI)) { /*if (parentSchema.AttributeFormDefault = XmlSchemaForm.Unqualified && childURI.Length == 0) { xs = parentSchema; add = false; break; }*/ xs = new XmlSchema(); xs.AttributeFormDefault = XmlSchemaForm.Unqualified; xs.ElementFormDefault = XmlSchemaForm.Qualified; if (childURI.Length != 0) xs.TargetNamespace = childURI; //schemas.Add(childURI, xs); this.schemaSet.Add(xs); if (prefix.Length != 0 && String.Compare(prefix, "xml", StringComparison.OrdinalIgnoreCase) != 0) NamespaceManager.AddNamespace(prefix, childURI); } else { ArrayList col = this.schemaSet.Schemas(childURI) as ArrayList; if (col != null && col.Count > 0) { xs = col[0] as XmlSchema; } } if (childURI.Length != 0) { XmlSchemaAttribute attributeReference = null; //see if the reference exists attributeReference = FindAttributeRef(searchCollection, localName, childURI); if (attributeReference == null) { attributeReference = new XmlSchemaAttribute(); attributeReference.RefName = new XmlQualifiedName(localName, childURI); if (bCreatingNewType && this.Occurrence == InferenceOption.Restricted) { attributeReference.Use = XmlSchemaUse.Required; } else { attributeReference.Use = XmlSchemaUse.Optional; } addLocation.Add(attributeReference); } returnedAttribute = attributeReference; //see if the attribute exists on the global level xsa = FindAttribute(xs.Items, localName); if (xsa == null) { xsa = new XmlSchemaAttribute(); xsa.Name = localName; xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType); xsa.LineNumber = AttributeType; //we use LineNumber to store flags of valid types xs.Items.Add(xsa); } else { if (xsa.Parent == null) { AttributeType = xsa.LineNumber; // we use LineNumber to store flags of valid types } else { AttributeType = GetSchemaType(xsa.SchemaTypeName); xsa.Parent = null; } xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType); xsa.LineNumber = AttributeType; // we use LineNumber to store flags of valid types } } else { xsa = FindAttribute(searchCollection, localName); if (xsa == null) { xsa = new XmlSchemaAttribute(); xsa.Name = localName; xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType); xsa.LineNumber = AttributeType; // we use LineNumber to store flags of valid types if (bCreatingNewType && this.Occurrence == InferenceOption.Restricted) xsa.Use = XmlSchemaUse.Required; else xsa.Use = XmlSchemaUse.Optional; addLocation.Add(xsa); if (xs.AttributeFormDefault != XmlSchemaForm.Unqualified) { xsa.Form = XmlSchemaForm.Unqualified; } } else { if (xsa.Parent == null) { AttributeType = xsa.LineNumber; // we use LineNumber to store flags of valid types } else { AttributeType = GetSchemaType(xsa.SchemaTypeName); xsa.Parent = null; } xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType); xsa.LineNumber = AttributeType; // we use LineNumber to store flags of valid types } returnedAttribute = xsa; } } string nullString = null; if (add && childURI != parentSchema.TargetNamespace) { foreach (XmlSchemaExternal external in parentSchema.Includes) { XmlSchemaImport import = external as XmlSchemaImport; if (import == null) { continue; } if (import.Namespace == childURI) { add = false; } } if (add) { XmlSchemaImport import = new XmlSchemaImport(); import.Schema = xs; if (childURI.Length != 0) { nullString = childURI; } import.Namespace = nullString; parentSchema.Includes.Add(import); } } return returnedAttribute; }
void ExportMembersMapSchema (XmlSchema schema, ClassMap map, XmlTypeMapping baseMap, XmlSchemaObjectCollection outAttributes, out XmlSchemaSequence particle, out XmlSchemaAnyAttribute anyAttribute) { particle = null; XmlSchemaSequence seq = new XmlSchemaSequence (); ICollection members = map.ElementMembers; if (members != null && !map.HasSimpleContent) { foreach (XmlTypeMapMemberElement member in members) { if (baseMap != null && DefinedInBaseMap (baseMap, member)) continue; Type memType = member.GetType(); if (memType == typeof(XmlTypeMapMemberFlatList)) { XmlSchemaParticle part = GetSchemaArrayElement (schema, member.ElementInfo); if (part != null) seq.Items.Add (part); } else if (memType == typeof(XmlTypeMapMemberAnyElement)) { seq.Items.Add (GetSchemaArrayElement (schema, member.ElementInfo)); } else if (memType == typeof(XmlTypeMapMemberElement)) { GetSchemaElement (schema, (XmlTypeMapElementInfo) member.ElementInfo [0], member.DefaultValue, true, new XmlSchemaObjectContainer (seq)); } else { GetSchemaElement (schema, (XmlTypeMapElementInfo) member.ElementInfo[0], true, new XmlSchemaObjectContainer (seq)); } } } if (seq.Items.Count > 0) particle = seq; // Write attributes ICollection attributes = map.AttributeMembers; if (attributes != null) { foreach (XmlTypeMapMemberAttribute attr in attributes) { if (baseMap != null && DefinedInBaseMap (baseMap, attr)) continue; outAttributes.Add (GetSchemaAttribute (schema, attr, true)); } } XmlTypeMapMember anyAttrMember = map.DefaultAnyAttributeMember; if (anyAttrMember != null) anyAttribute = new XmlSchemaAnyAttribute (); else anyAttribute = null; }
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); }
private void AddSubstElementRecursively (XmlSchemaObjectCollection col, XmlSchemaElement el) { if (el.SubstitutingElements != null) for (int i = 0; i < el.SubstitutingElements.Count; i++) this.AddSubstElementRecursively (col, el.SubstitutingElements [i] as XmlSchemaElement); if (!col.Contains (el)) col.Add (el); }
void DoCompile(ValidationEventHandler handler, Hashtable handledUris, XmlSchemaSet col, XmlResolver resolver) { SetParent(); CompilationId = col.CompilationId; schemas = col; if (!schemas.Contains(this)) // e.g. xs:import { schemas.Add(this); } attributeGroups.Clear(); attributes.Clear(); elements.Clear(); groups.Clear(); notations.Clear(); schemaTypes.Clear(); //1. Union and List are not allowed in block default if (BlockDefault != XmlSchemaDerivationMethod.All) { if ((BlockDefault & XmlSchemaDerivationMethod.List) != 0) { error(handler, "list is not allowed in blockDefault attribute"); } if ((BlockDefault & XmlSchemaDerivationMethod.Union) != 0) { error(handler, "union is not allowed in blockDefault attribute"); } } //2. Substitution is not allowed in finaldefault. if (FinalDefault != XmlSchemaDerivationMethod.All) { if ((FinalDefault & XmlSchemaDerivationMethod.Substitution) != 0) { error(handler, "substitution is not allowed in finalDefault attribute"); } } //3. id must be of type ID XmlSchemaUtil.CompileID(Id, this, col.IDCollection, handler); //4. targetNamespace should be of type anyURI or absent if (TargetNamespace != null) { if (TargetNamespace.Length == 0) { error(handler, "The targetNamespace attribute cannot have have empty string as its value."); } if (!XmlSchemaUtil.CheckAnyUri(TargetNamespace)) { error(handler, TargetNamespace + " is not a valid value for targetNamespace attribute of schema"); } } //5. version should be of type normalizedString if (!XmlSchemaUtil.CheckNormalizedString(Version)) { error(handler, Version + "is not a valid value for version attribute of schema"); } // Compile the content of this schema compilationItems = new XmlSchemaObjectCollection(); for (int i = 0; i < Items.Count; i++) { compilationItems.Add(Items [i]); } // First, we run into inclusion schemas to collect // compilation target items into compiledItems. for (int i = 0; i < Includes.Count; i++) { XmlSchemaExternal ext = Includes [i] as XmlSchemaExternal; if (ext == null) { error(handler, String.Format("Object of Type {0} is not valid in Includes Property of XmlSchema", Includes [i].GetType().Name)); continue; } if (ext.SchemaLocation == null) { continue; } Stream stream = null; string url = null; if (resolver != null) { url = GetResolvedUri(resolver, ext.SchemaLocation); if (handledUris.Contains(url)) { // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur. continue; } handledUris.Add(url, url); try { stream = resolver.GetEntity(new Uri(url), null, typeof(Stream)) as Stream; } catch (Exception) { // LAMESPEC: This is not good way to handle errors, but since we cannot know what kind of XmlResolver will come, so there are no mean to avoid this ugly catch. warn(handler, "Could not resolve schema location URI: " + url); stream = null; } } // Process redefinition children in advance. XmlSchemaRedefine redefine = Includes [i] as XmlSchemaRedefine; if (redefine != null) { for (int j = 0; j < redefine.Items.Count; j++) { XmlSchemaObject redefinedObj = redefine.Items [j]; redefinedObj.isRedefinedComponent = true; redefinedObj.isRedefineChild = true; if (redefinedObj is XmlSchemaType || redefinedObj is XmlSchemaGroup || redefinedObj is XmlSchemaAttributeGroup) { compilationItems.Add(redefinedObj); } else { error(handler, "Redefinition is only allowed to simpleType, complexType, group and attributeGroup."); } } } XmlSchema includedSchema = null; if (stream == null) { // It is missing schema components. missedSubComponents = true; continue; } else { XmlTextReader xtr = null; try { xtr = new XmlTextReader(url, stream, nameTable); includedSchema = XmlSchema.Read(xtr, handler); } finally { if (xtr != null) { xtr.Close(); } } includedSchema.schemas = schemas; } includedSchema.SetParent(); ext.Schema = includedSchema; // Set - actual - target namespace for the included schema * before compilation*. XmlSchemaImport import = ext as XmlSchemaImport; if (import != null) { if (TargetNamespace == includedSchema.TargetNamespace) { error(handler, "Target namespace must be different from that of included schema."); continue; } else if (includedSchema.TargetNamespace != import.Namespace) { error(handler, "Attribute namespace and its importing schema's target namespace must be the same."); continue; } } else { if (TargetNamespace == null && includedSchema.TargetNamespace != null) { error(handler, "Target namespace is required to include a schema which has its own target namespace"); continue; } else if (TargetNamespace != null && includedSchema.TargetNamespace == null) { includedSchema.TargetNamespace = TargetNamespace; } } // Do not compile included schema here. AddExternalComponentsTo(includedSchema, compilationItems); } // Compilation phase. // At least each Compile() must give unique (qualified) name for each component. // It also checks self-resolvable properties correctness. // Post compilation schema information contribution is not done here. // It should be done by Validate(). for (int i = 0; i < compilationItems.Count; i++) { XmlSchemaObject obj = compilationItems [i]; if (obj is XmlSchemaAnnotation) { int numerr = ((XmlSchemaAnnotation)obj).Compile(handler, this); errorCount += numerr; } else if (obj is XmlSchemaAttribute) { XmlSchemaAttribute attr = (XmlSchemaAttribute)obj; int numerr = attr.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable(Attributes, attr, attr.QualifiedName, handler); } } else if (obj is XmlSchemaAttributeGroup) { XmlSchemaAttributeGroup attrgrp = (XmlSchemaAttributeGroup)obj; int numerr = attrgrp.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( AttributeGroups, attrgrp, attrgrp.QualifiedName, handler); } } else if (obj is XmlSchemaComplexType) { XmlSchemaComplexType ctype = (XmlSchemaComplexType)obj; int numerr = ctype.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( schemaTypes, ctype, ctype.QualifiedName, handler); } } else if (obj is XmlSchemaSimpleType) { XmlSchemaSimpleType stype = (XmlSchemaSimpleType)obj; stype.islocal = false; //This simple type is toplevel int numerr = stype.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( SchemaTypes, stype, stype.QualifiedName, handler); } } else if (obj is XmlSchemaElement) { XmlSchemaElement elem = (XmlSchemaElement)obj; elem.parentIsSchema = true; int numerr = elem.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Elements, elem, elem.QualifiedName, handler); } } else if (obj is XmlSchemaGroup) { XmlSchemaGroup grp = (XmlSchemaGroup)obj; int numerr = grp.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Groups, grp, grp.QualifiedName, handler); } } else if (obj is XmlSchemaNotation) { XmlSchemaNotation ntn = (XmlSchemaNotation)obj; int numerr = ntn.Compile(handler, this); errorCount += numerr; if (numerr == 0) { XmlSchemaUtil.AddToTable( Notations, ntn, ntn.QualifiedName, handler); } } else { ValidationHandler.RaiseValidationEvent( handler, null, String.Format("Object of Type {0} is not valid in Item Property of Schema", obj.GetType().Name), null, this, null, XmlSeverityType.Error); } } }
internal XmlSchemaObjectCollection Clone() { XmlSchemaObjectCollection objects = new XmlSchemaObjectCollection(); objects.Add(this); return objects; }
private XmlSchemaElement AddElement(string localName, string prefix, string childURI, XmlSchema parentSchema, XmlSchemaObjectCollection addLocation, int positionWithinCollection) { if (childURI == XmlSchema.Namespace) { throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0); } XmlSchemaElement xse = null; XmlSchemaElement returnedElement = xse; //this value will change to elementReference if childURI!= parentURI XmlSchema xs = null; bool bCreatingNewType = true; if (childURI == String.Empty) { childURI = null; } // The new element belongs to the same ns as parent and addlocation is not null if (parentSchema != null && childURI == parentSchema.TargetNamespace) { xse = new XmlSchemaElement(); xse.Name = localName; xs = parentSchema; if (xs.ElementFormDefault != XmlSchemaForm.Qualified && addLocation != null) { xse.Form = XmlSchemaForm.Qualified; } } else if (schemaSet.Contains(childURI)) { xse = this.FindGlobalElement(childURI, localName, out xs); if (xse == null) { ArrayList col = this.schemaSet.Schemas(childURI)as ArrayList; if (col != null && col.Count > 0 ) { xs = col[0] as XmlSchema; } xse = new XmlSchemaElement(); xse.Name = localName; xs.Items.Add(xse); } else bCreatingNewType = false; } else { xs = CreateXmlSchema(childURI); if (prefix.Length!=0) NamespaceManager.AddNamespace(prefix, childURI); xse=new XmlSchemaElement(); xse.Name = localName; xs.Items.Add(xse); //add global element declaration only when creating new schema } if (parentSchema == null) { parentSchema = xs; this.rootSchema = parentSchema; } if (childURI != parentSchema.TargetNamespace ) { bool add = true; for (int i = 0; i < parentSchema.Includes.Count; ++i) { XmlSchemaImport import = parentSchema.Includes[i] as XmlSchemaImport; if (import == null) { continue; } //Debug.WriteLine(import.Schema.TargetNamespace); if (import.Namespace == childURI) { add = false; } } if (add) { XmlSchemaImport import = new XmlSchemaImport(); import.Schema = xs; import.Namespace = childURI; parentSchema.Includes.Add(import); } } returnedElement = xse; if (addLocation != null) { if (childURI == parentSchema.TargetNamespace ) { if (this.Occurrence == InferenceOption.Relaxed /*&& parentSchema.Items != addLocation*/) { xse.MinOccurs = 0; } if (positionWithinCollection == -1) { positionWithinCollection = addLocation.Add(xse); } else { addLocation.Insert(positionWithinCollection, xse); } } else { XmlSchemaElement elementReference = new XmlSchemaElement(); elementReference.RefName = new XmlQualifiedName(localName, childURI); if (this.Occurrence == InferenceOption.Relaxed) { elementReference.MinOccurs = 0; } if (positionWithinCollection == -1) { positionWithinCollection = addLocation.Add(elementReference); } else { addLocation.Insert(positionWithinCollection, elementReference); } returnedElement = elementReference; /* if (childURI == XmlSchema.Namespace) { schemaList.Add(new ReplaceList(addLocation, positionWithinCollection)); }*/ } } InferElement(xse, bCreatingNewType, xs); return returnedElement; }
void AddExternalComponentsTo (XmlSchema s, XmlSchemaObjectCollection items, ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver, XmlSchemaSet col) { foreach (XmlSchemaExternal ext in s.Includes) ProcessExternal (handler, handledUris, resolver, ext, col); // if (ext.Schema != null) // AddExternalComponentsTo (ext.Schema, items); foreach (XmlSchemaObject obj in s.Items) items.Add (obj); }
internal override bool ValidateDerivationByRestriction (XmlSchemaParticle baseParticle, ValidationEventHandler h, XmlSchema schema, bool raiseError) { if (this == baseParticle) // quick check return true; XmlSchemaElement el = baseParticle as XmlSchemaElement; if (el != null) { // Forbidden if (raiseError) error (h, "Invalid sequence paricle derivation."); return false; } XmlSchemaSequence seq = baseParticle as XmlSchemaSequence; if (seq != null) { // Recurse if (!ValidateOccurenceRangeOK (seq, h, schema, raiseError)) return false; // If it is totally optional, then ignore their contents. if (seq.ValidatedMinOccurs == 0 && seq.ValidatedMaxOccurs == 0 && this.ValidatedMinOccurs == 0 && this.ValidatedMaxOccurs == 0) return true; return ValidateRecurse (seq, h, schema, raiseError); } XmlSchemaAll all = baseParticle as XmlSchemaAll; if (all != null) { // RecurseUnordered XmlSchemaObjectCollection already = new XmlSchemaObjectCollection (); for (int i = 0; i < this.Items.Count; i++) { XmlSchemaElement de = this.Items [i] as XmlSchemaElement; if (de == null) { if (raiseError) error (h, "Invalid sequence particle derivation by restriction from all."); return false; } foreach (XmlSchemaElement e in all.Items) { if (e.QualifiedName == de.QualifiedName) { if (already.Contains (e)) { if (raiseError) error (h, "Base element particle is mapped to the derived element particle in a sequence two or more times."); return false; } else { already.Add (e); if (!de.ValidateDerivationByRestriction (e, h, schema, raiseError)) return false; } } } } foreach (XmlSchemaElement e in all.Items) if (!already.Contains (e)) if (!e.ValidateIsEmptiable ()) { if (raiseError) error (h, "In base -all- particle, mapping-skipped base element which is not emptiable was found."); return false; } return true; } XmlSchemaAny any = baseParticle as XmlSchemaAny; if (any != null) { // NSRecurseCheckCardinality return ValidateNSRecurseCheckCardinality (any, h, schema, raiseError); } XmlSchemaChoice choice = baseParticle as XmlSchemaChoice; if (choice != null) { // MapAndSum // In fact it is not Recurse, but it looks almost common. return ValidateSeqRecurseMapSumCommon (choice, h, schema, false, true, raiseError); } return true; }
internal override void AddAnnotation(XmlSchemaAnnotation annotation) { _items.Add(annotation); }
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)); }
/// <summary> /// Verifies that the current element has its corresponding element in the sequence and order is the same. /// If the order is not the same, it changes the particle from Sequence to Sequence with Choice. /// If there is more elements of the same kind in the sequence, sets maxOccurs to unbounded /// </summary> /// <param name="bCreatingNewType">True if this is a new type. This is important for setting minOccurs=0 for elements that did not exist in a particle.</param> /// <param name="xtr">text reader positioned to the current element</param> /// <param name="ct">complex type with Sequence or Choice Particle</param> /// <param name="lastUsedSeqItem">ordinal number in the sequence to indicate current sequence position</param> /// <param name="itemsMadeOptional">hashtable of elements with minOccurs changed to 0 in order to satisfy sequence requirements. These elements will be rolled back if Sequence becomes Sequence of Choice.</param> /// <param name="bParticleChanged">This indicates to the caller if Sequence was changed to Choice</param> internal XmlSchemaElement FindMatchingElement(bool bCreatingNewType, XmlReader xtr,XmlSchemaComplexType ct, ref int lastUsedSeqItem, ref bool bParticleChanged, XmlSchema parentSchema, bool setMaxoccurs) { if (xtr.NamespaceURI == XmlSchema.Namespace) { throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0); } bool bItemNotUsedYet = ((lastUsedSeqItem == -1)? true: false); XmlSchemaObjectCollection minOccursCandidates = new XmlSchemaObjectCollection(); //elements that are skipped in the sequence and need minOccurs modified. if (ct.Particle.GetType() == typeof (XmlSchemaSequence)) { string childURI = xtr.NamespaceURI; if (childURI.Length == 0) { childURI = null; } XmlSchemaSequence xss = (XmlSchemaSequence) ct.Particle; if (xss.Items.Count < 1 && !bCreatingNewType) { lastUsedSeqItem = 0; XmlSchemaElement e = AddElement(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, parentSchema, xss.Items,-1); e.MinOccurs = 0; return e; } if (xss.Items[0].GetType() == typeof (XmlSchemaChoice)) { // <sequence minOccurs="0" maxOccurs="unbounded"><choice><element>...</choice></sequence> XmlSchemaChoice xsch = (XmlSchemaChoice) xss.Items[0]; for (int i = 0; i < xsch.Items.Count; ++i) { XmlSchemaElement el = xsch.Items[i] as XmlSchemaElement; if (el == null) { throw new XmlSchemaInferenceException(Res.SchInf_UnknownParticle, 0, 0); } if ((el.Name == xtr.LocalName) &&( parentSchema.TargetNamespace == childURI)) { // element is in the same namespace InferElement(el, false, parentSchema); SetMinMaxOccurs(el, setMaxoccurs); return el; } else if ((el.RefName.Name == xtr.LocalName) && (el.RefName.Namespace == xtr.NamespaceURI)) { XmlSchemaElement referencedElement = FindGlobalElement(childURI, xtr.LocalName, out parentSchema); InferElement(referencedElement, false, parentSchema); SetMinMaxOccurs(el, setMaxoccurs); return referencedElement; } } XmlSchemaElement subElement = AddElement(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, parentSchema, xsch.Items,-1); return subElement; } else { //this should be sequence of elements int iSeqItem = 0; //iterator through schema sequence items if (lastUsedSeqItem >= 0) iSeqItem = lastUsedSeqItem; XmlSchemaParticle particle = xss.Items[iSeqItem] as XmlSchemaParticle; XmlSchemaElement el = particle as XmlSchemaElement; if (el == null) { throw new XmlSchemaInferenceException(Res.SchInf_UnknownParticle, 0, 0); } if (el.Name == xtr.LocalName && parentSchema.TargetNamespace == childURI) { if (!bItemNotUsedYet) //read: if item was already used one or more times el.MaxOccurs = decimal.MaxValue; //set it to unbounded lastUsedSeqItem = iSeqItem; InferElement(el, false, parentSchema); SetMinMaxOccurs(el, false); return el; } else if (el.RefName.Name == xtr.LocalName && el.RefName.Namespace == xtr.NamespaceURI) { if (!bItemNotUsedYet) //read: if item was already used one or more times el.MaxOccurs = decimal.MaxValue; //set it to unbounded lastUsedSeqItem = iSeqItem; XmlSchemaElement referencedElement = FindGlobalElement(childURI, xtr.LocalName, out parentSchema); InferElement(referencedElement, false, parentSchema); SetMinMaxOccurs(el, false); return el; } if (bItemNotUsedYet && el.MinOccurs!=decimal.Zero) minOccursCandidates.Add(el); iSeqItem++; while (iSeqItem < xss.Items.Count) { particle = xss.Items[iSeqItem] as XmlSchemaParticle; el = particle as XmlSchemaElement; if (el == null) { throw new XmlSchemaInferenceException(Res.SchInf_UnknownParticle, 0, 0); } if (el.Name == xtr.LocalName && parentSchema.TargetNamespace == childURI) { lastUsedSeqItem = iSeqItem; for (int i = 0; i < minOccursCandidates.Count; ++i) { ((XmlSchemaElement) minOccursCandidates[i]).MinOccurs = decimal.Zero; } InferElement(el, false, parentSchema); SetMinMaxOccurs(el, setMaxoccurs); return el; } else if (el.RefName.Name == xtr.LocalName && el.RefName.Namespace == xtr.NamespaceURI) { lastUsedSeqItem = iSeqItem; for (int i = 0; i < minOccursCandidates.Count; ++i) { ((XmlSchemaElement) minOccursCandidates[i]).MinOccurs = decimal.Zero; } XmlSchemaElement referencedElement = FindGlobalElement(childURI, xtr.LocalName, out parentSchema); InferElement(referencedElement, false, parentSchema); SetMinMaxOccurs(el, setMaxoccurs); return referencedElement; } minOccursCandidates.Add(el); iSeqItem++; } //element not found in the sequence order, if it is found out of order change Sequence of elements to Sequence of Choices otherwise insert into sequence as optional XmlSchemaElement subElement = null; XmlSchemaElement actualElement = null; // if (parentSchema.TargetNamespace == childURI) { subElement = FindElement(xss.Items, xtr.LocalName); actualElement = subElement; } else { subElement = FindElementRef(xss.Items, xtr.LocalName, xtr.NamespaceURI); if (subElement != null) { actualElement = FindGlobalElement(childURI, xtr.LocalName, out parentSchema); } } if (null != subElement) { XmlSchemaChoice xsc = new XmlSchemaChoice(); xsc.MaxOccurs = decimal.MaxValue; SetMinMaxOccurs(subElement, setMaxoccurs); InferElement(actualElement, false, parentSchema); for (int i = 0; i < xss.Items.Count; ++i) { xsc.Items.Add(CreateNewElementforChoice((XmlSchemaElement) xss.Items[i])); } xss.Items.Clear(); xss.Items.Add(xsc); return subElement; } else { subElement = AddElement(xtr.LocalName, xtr.Prefix, xtr.NamespaceURI, parentSchema, xss.Items, ++lastUsedSeqItem); if (!bCreatingNewType) subElement.MinOccurs = decimal.Zero; return subElement; } } } else { throw new XmlSchemaInferenceException(Res.SchInf_noseq, 0, 0); } }
// Attributes might be redefined, so there is an existing attribute for the same name, skip it. // FIXME: this is nothing more than just a hack. // Basically it should use // XmlSchemaComplexType.AttributeUses. XmlSchemaObjectCollection CollectAttributeUsesNonOverlap ( XmlSchemaObjectCollection src, ClassMap map) { XmlSchemaObjectCollection atts = new XmlSchemaObjectCollection (); foreach (var a in EnumerateAttributes (src, new List<XmlSchemaAttributeGroup> ())) if (map.GetAttribute (a.QualifiedName.Name, a.QualifiedName.Namespace) == null) atts.Add (a); return atts; }
private XmlSchemaAttribute AddAttribute(string localName, string prefix, string childURI, string attrValue, bool bCreatingNewType, XmlSchema parentSchema, XmlSchemaObjectCollection addLocation, XmlSchemaObjectTable compiledAttributes) { if (childURI == XmlSchema.Namespace) { throw new XmlSchemaInferenceException(Res.SchInf_schema, 0, 0); } XmlSchemaAttribute xsa = null; int AttributeType = -1; XmlSchemaAttribute returnedAttribute = null; //this value will change to attributeReference if childURI!= parentURI XmlSchema xs = null; bool add = true; Debug.Assert(compiledAttributes != null); //AttributeUses is never null // First we need to look into the already compiled attributes // (they come from the schemaset which we got on input) // If there are none or we don't find it there, then we must search the list of attributes // where we are going to add a new one (if it doesn't exist). // This is necessary to avoid adding duplicate attribute declarations. ICollection searchCollectionPrimary, searchCollectionSecondary; if (compiledAttributes.Count > 0) { searchCollectionPrimary = compiledAttributes.Values; searchCollectionSecondary = addLocation; } else { searchCollectionPrimary = addLocation; searchCollectionSecondary = null; } if (childURI == XmlReservedNs.NsXml) { XmlSchemaAttribute attributeReference = null; //see if the reference exists attributeReference = FindAttributeRef(searchCollectionPrimary, localName, childURI); if (attributeReference == null && searchCollectionSecondary != null) { attributeReference = FindAttributeRef(searchCollectionSecondary, localName, childURI); } if (attributeReference == null) { attributeReference = new XmlSchemaAttribute(); attributeReference.RefName = new XmlQualifiedName(localName, childURI); if (bCreatingNewType && this.Occurrence == InferenceOption.Restricted) { attributeReference.Use = XmlSchemaUse.Required; } else { attributeReference.Use = XmlSchemaUse.Optional; } addLocation.Add(attributeReference); } returnedAttribute = attributeReference; } else { if (childURI.Length == 0) { xs = parentSchema; add = false; } else if (childURI != null && !schemaSet.Contains(childURI)) { /*if (parentSchema.AttributeFormDefault = XmlSchemaForm.Unqualified && childURI.Length == 0) { xs = parentSchema; add = false; break; }*/ xs = new XmlSchema(); xs.AttributeFormDefault = XmlSchemaForm.Unqualified; xs.ElementFormDefault = XmlSchemaForm.Qualified; if (childURI.Length != 0) xs.TargetNamespace = childURI; //schemas.Add(childURI, xs); this.schemaSet.Add(xs); if (prefix.Length != 0 && String.Compare(prefix, "xml", StringComparison.OrdinalIgnoreCase) != 0) NamespaceManager.AddNamespace(prefix, childURI); } else { ArrayList col = this.schemaSet.Schemas(childURI) as ArrayList; if (col != null && col.Count > 0) { xs = col[0] as XmlSchema; } } if (childURI.Length != 0) // { XmlSchemaAttribute attributeReference = null; //see if the reference exists attributeReference = FindAttributeRef(searchCollectionPrimary, localName, childURI); if (attributeReference == null & searchCollectionSecondary != null) { attributeReference = FindAttributeRef(searchCollectionSecondary, localName, childURI); } if (attributeReference == null) { attributeReference = new XmlSchemaAttribute(); attributeReference.RefName = new XmlQualifiedName(localName, childURI); if (bCreatingNewType && this.Occurrence == InferenceOption.Restricted) { attributeReference.Use = XmlSchemaUse.Required; } else { attributeReference.Use = XmlSchemaUse.Optional; } addLocation.Add(attributeReference); } returnedAttribute = attributeReference; //see if the attribute exists on the global level xsa = FindAttribute(xs.Items, localName); if (xsa == null) { xsa = new XmlSchemaAttribute(); xsa.Name = localName; xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType); xsa.LineNumber = AttributeType; //we use LineNumber to store flags of valid types xs.Items.Add(xsa); } else { if (xsa.Parent == null) { AttributeType = xsa.LineNumber; // we use LineNumber to store flags of valid types } else { AttributeType = GetSchemaType(xsa.SchemaTypeName); xsa.Parent = null; } xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType); xsa.LineNumber = AttributeType; // we use LineNumber to store flags of valid types } } else { xsa = FindAttribute(searchCollectionPrimary, localName); if (xsa == null && searchCollectionSecondary != null) { xsa = FindAttribute(searchCollectionSecondary, localName); } if (xsa == null) { xsa = new XmlSchemaAttribute(); xsa.Name = localName; xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType); xsa.LineNumber = AttributeType; // we use LineNumber to store flags of valid types if (bCreatingNewType && this.Occurrence == InferenceOption.Restricted) xsa.Use = XmlSchemaUse.Required; else xsa.Use = XmlSchemaUse.Optional; addLocation.Add(xsa); if (xs.AttributeFormDefault != XmlSchemaForm.Unqualified) { xsa.Form = XmlSchemaForm.Unqualified; } } else { if (xsa.Parent == null) { AttributeType = xsa.LineNumber; // we use LineNumber to store flags of valid types } else { AttributeType = GetSchemaType(xsa.SchemaTypeName); xsa.Parent = null; } xsa.SchemaTypeName = RefineSimpleType(attrValue, ref AttributeType); xsa.LineNumber = AttributeType; // we use LineNumber to store flags of valid types } returnedAttribute = xsa; } } string nullString = null; if (add && childURI != parentSchema.TargetNamespace) { for (int i = 0; i < parentSchema.Includes.Count; ++i) { XmlSchemaImport import = parentSchema.Includes[i] as XmlSchemaImport; if (import == null) { continue; } if (import.Namespace == childURI) { add = false; } } if (add) { XmlSchemaImport import = new XmlSchemaImport(); import.Schema = xs; if (childURI.Length != 0) { nullString = childURI; } import.Namespace = nullString; parentSchema.Includes.Add(import); } } return returnedAttribute; }
internal void ProcessAttributes(ref XmlSchemaElement xse, XmlSchemaType effectiveSchemaType, bool bCreatingNewType, XmlSchema parentSchema) { XmlSchemaObjectCollection attributesInInstance = new XmlSchemaObjectCollection(); XmlSchemaComplexType ct = effectiveSchemaType as XmlSchemaComplexType; do { if (this.xtr.NamespaceURI == "http://www.w3.org/2001/XMLSchema") { throw new XmlSchemaInferenceException("SchInf_schema", 0, 0); } if (this.xtr.NamespaceURI == "http://www.w3.org/2000/xmlns/") { if (this.xtr.Prefix == "xmlns") { this.NamespaceManager.AddNamespace(this.xtr.LocalName, this.xtr.Value); } } else if (this.xtr.NamespaceURI == "http://www.w3.org/2001/XMLSchema-instance") { string localName = this.xtr.LocalName; if (localName != "nil") { if (((localName != "type") && (localName != "schemaLocation")) && (localName != "noNamespaceSchemaLocation")) { throw new XmlSchemaInferenceException("Sch_NotXsiAttribute", localName); } } else { xse.IsNillable = true; } } else { if ((ct == null) || (ct == XmlSchemaComplexType.AnyType)) { ct = new XmlSchemaComplexType(); xse.SchemaType = ct; } XmlSchemaAttribute item = null; if (((effectiveSchemaType != null) && (effectiveSchemaType.Datatype != null)) && !xse.SchemaTypeName.IsEmpty) { XmlSchemaSimpleContent content = new XmlSchemaSimpleContent(); ct.ContentModel = content; XmlSchemaSimpleContentExtension extension = new XmlSchemaSimpleContentExtension(); content.Content = extension; extension.BaseTypeName = xse.SchemaTypeName; extension.LineNumber = xse.LineNumber; xse.LineNumber = 0; xse.SchemaTypeName = XmlQualifiedName.Empty; } if (ct.ContentModel != null) { XmlSchemaSimpleContentExtension extension2 = this.CheckSimpleContentExtension(ct); item = this.AddAttribute(this.xtr.LocalName, this.xtr.Prefix, this.xtr.NamespaceURI, this.xtr.Value, bCreatingNewType, parentSchema, extension2.Attributes, ct.AttributeUses); } else { item = this.AddAttribute(this.xtr.LocalName, this.xtr.Prefix, this.xtr.NamespaceURI, this.xtr.Value, bCreatingNewType, parentSchema, ct.Attributes, ct.AttributeUses); } if (item != null) { attributesInInstance.Add(item); } } } while (this.xtr.MoveToNextAttribute()); if (!bCreatingNewType && (ct != null)) { this.MakeExistingAttributesOptional(ct, attributesInInstance); } }
void ProcessExternal(ValidationEventHandler handler, Hashtable handledUris, XmlResolver resolver, XmlSchemaExternal ext, XmlSchemaSet col) { if (ext == null) { error(handler, String.Format("Object of Type {0} is not valid in Includes Property of XmlSchema", ext.GetType().Name)); return; } // The only case we want to handle where the SchemaLocation is null is if the external is an import. XmlSchemaImport import = ext as XmlSchemaImport; if (ext.SchemaLocation == null && import == null) { return; } XmlSchema includedSchema = null; if (ext.SchemaLocation != null) { Stream stream = null; string url = null; if (resolver != null) { url = GetResolvedUri(resolver, ext.SchemaLocation); if (handledUris.Contains(url)) { // This schema is already handled, so simply skip (otherwise, duplicate definition errrors occur. return; } handledUris.Add(url, url); try { stream = resolver.GetEntity(new Uri(url), null, typeof(Stream)) as Stream; } catch (Exception) { // LAMESPEC: This is not good way to handle errors, but since we cannot know what kind of XmlResolver will come, so there are no mean to avoid this ugly catch. warn(handler, "Could not resolve schema location URI: " + url); stream = null; } } // Process redefinition children in advance. XmlSchemaRedefine redefine = ext as XmlSchemaRedefine; if (redefine != null) { for (int j = 0; j < redefine.Items.Count; j++) { XmlSchemaObject redefinedObj = redefine.Items [j]; redefinedObj.isRedefinedComponent = true; redefinedObj.isRedefineChild = true; if (redefinedObj is XmlSchemaType || redefinedObj is XmlSchemaGroup || redefinedObj is XmlSchemaAttributeGroup) { compilationItems.Add(redefinedObj); } else { error(handler, "Redefinition is only allowed to simpleType, complexType, group and attributeGroup."); } } } if (stream == null) { // It is missing schema components. missedSubComponents = true; return; } else { XmlTextReader xtr = null; try { xtr = new XmlTextReader(url, stream, nameTable); includedSchema = XmlSchema.Read(xtr, handler); } finally { if (xtr != null) { xtr.Close(); } } includedSchema.schemas = schemas; } includedSchema.SetParent(); ext.Schema = includedSchema; } // Set - actual - target namespace for the included schema * before compilation*. if (import != null) { if (ext.Schema == null && ext.SchemaLocation == null) { // if a schema location wasn't specified, check the other schemas we have to see if one of those // is a match. foreach (XmlSchema schema in col.Schemas()) { if (schema.TargetNamespace == import.Namespace) { includedSchema = schema; includedSchema.schemas = schemas; includedSchema.SetParent(); ext.Schema = includedSchema; break; } } // handle case where target namespace doesn't exist in schema collection - i.e can't find it at all if (includedSchema == null) { return; } } else if (includedSchema != null) { if (TargetNamespace == includedSchema.TargetNamespace) { error(handler, "Target namespace must be different from that of included schema."); return; } else if (includedSchema.TargetNamespace != import.Namespace) { error(handler, "Attribute namespace and its importing schema's target namespace must be the same."); return; } } } else if (includedSchema != null) { if (TargetNamespace == null && includedSchema.TargetNamespace != null) { error(handler, "Target namespace is required to include a schema which has its own target namespace"); return; } else if (TargetNamespace != null && includedSchema.TargetNamespace == null) { includedSchema.TargetNamespace = TargetNamespace; } } // Do not compile included schema here. if (includedSchema != null) { AddExternalComponentsTo(includedSchema, compilationItems, handler, handledUris, resolver, col); } }
internal XmlSchemaObjectCollection GetParticleItems(XmlSchemaParticle pt) { if (pt is XmlSchemaSequence) { return ((XmlSchemaSequence) pt).Items; } if (pt is XmlSchemaAll) { return ((XmlSchemaAll) pt).Items; } if (pt is XmlSchemaChoice) { return ((XmlSchemaChoice) pt).Items; } if (!(pt is XmlSchemaAny)) { if (pt is XmlSchemaElement) { XmlSchemaObjectCollection objects = new XmlSchemaObjectCollection(); objects.Add(pt); return objects; } if (pt is XmlSchemaGroupRef) { return this.GetParticleItems(((XmlSchemaGroupRef) pt).Particle); } } return null; }