/**//// <summary> /// 获理节点 /// </summary> /// <returns></returns> public static System.Collections.Generic.List <XmlSchemaElement> GetDatas() { XmlSchemaSet xsSet = new XmlSchemaSet(); xsSet.Add("", GetSchemaPath); xsSet.Compile(); XmlSchema schema = null; foreach (XmlSchema xs in xsSet.Schemas()) { schema = xs; } System.Collections.Generic.List <XmlSchemaElement> elements = new System.Collections.Generic.List <XmlSchemaElement>(); foreach (XmlSchemaObject obj in schema.Elements.Values) { if (obj.GetType() == typeof(XmlSchemaElement)) { elements.Add((XmlSchemaElement)obj); } } return(elements); } /**//// <summary> /// 添加元素 /// </summary> /// <param name="sourceXsd"></param> /// <param name="titles"></param> /// <param name="sourceXml"></param> /// <param name="sourceNd"></param> /// <param name="values"></param> public static void AddElement(XmlSchemaObject sourceXsd, Hashtable titles, XmlDocument sourceXml, XmlNode sourceNd, string[] values) { if (sourceXsd.GetType() == typeof(XmlSchemaChoice)) { XmlSchemaChoice choice = sourceXsd as XmlSchemaChoice; decimal min = choice.MinOccurs; foreach (XmlSchemaObject item in choice.Items) { if (item.GetType() == typeof(XmlSchemaElement)) { string name = ((XmlSchemaElement)item).Name; if (titles.ContainsKey(name)) { XmlElement element = sourceXml.CreateElement(name); // element.InnerText = ((Excel.Range)st.Cells[rowIndex, (int)titles[name]]).Value2.ToString(); element.InnerText = values[(int)titles[name]]; sourceNd.AppendChild(element); } } else { AddElement(item, titles, sourceXml, sourceNd, values); } } } else if (sourceXsd.GetType() == typeof(XmlSchemaElement)) { string name = ((XmlSchemaElement)sourceXsd).Name; if (titles.ContainsKey(name)) { XmlElement element = sourceXml.CreateElement(name); element.InnerText = values[(int)titles[name]]; sourceNd.AppendChild(element); } } else if (sourceXsd.GetType() == typeof(XmlSchemaSequence)) { foreach (XmlSchemaObject childItem in ((XmlSchemaSequence)sourceXsd).Items) { if (childItem.GetType() == typeof(XmlSchemaElement)) { string name = ((XmlSchemaElement)childItem).Name; if (titles.ContainsKey(name)) { XmlElement element = sourceXml.CreateElement(name); element.InnerText = values[(int)titles[name]]; sourceNd.AppendChild(element); } } else { AddElement(childItem, titles, sourceXml, sourceNd, values); } } } else { return; } }
public XsdValidationState Create(XmlSchemaObject xsobj) { string typeName = xsobj.GetType().Name; switch (typeName) { case "XmlSchemaElement": return(AddElement((XmlSchemaElement)xsobj)); case "XmlSchemaSequence": return(AddSequence((XmlSchemaSequence)xsobj)); case "XmlSchemaChoice": return(AddChoice((XmlSchemaChoice)xsobj)); case "XmlSchemaAll": return(AddAll((XmlSchemaAll)xsobj)); case "XmlSchemaAny": return(AddAny((XmlSchemaAny)xsobj)); case "EmptyParticle": return(AddEmpty()); default: // GroupRef should not appear throw new InvalidOperationException("Should not occur."); } }
private static string GetUniqueName(XmlSchemaObject schemaObj) { if (schemaObj is XmlSchemaType) { return(XmlConvert.DecodeName(((XmlSchemaType)schemaObj).QualifiedName.ToString())); } else if (schemaObj is XmlSchemaElement) { string parentName; // For Data Contracts which use inheritance, the XML schemas (XSDs) are a bit more complex. // Instead of the actual "class" node being two level above, it will be four levels above. // We need to handle this here, to properly handle subclasses data contracts. if (schemaObj.Parent.Parent is XmlSchemaComplexContentExtension) { parentName = GetUniqueName(schemaObj.Parent.Parent.Parent.Parent); } else { parentName = GetUniqueName(schemaObj.Parent.Parent); } return(parentName + "." + XmlConvert.DecodeName(((XmlSchemaElement)schemaObj).Name)); } else if (schemaObj is XmlSchemaEnumerationFacet) { string parentName = GetUniqueName(schemaObj.Parent.Parent); return(parentName + "." + XmlConvert.DecodeName(((XmlSchemaEnumerationFacet)schemaObj).Value)); } throw new NotImplementedException(String.Format( "Unknown schema object detected: {0}, at line number {1}, position {2}", schemaObj.GetType().FullName, schemaObj.LineNumber, schemaObj.LinePosition)); }
public XsdValidationState Create(XmlSchemaObject xsobj) { string name = xsobj.GetType().Name; string text = name; switch (text) { case "XmlSchemaElement": return(this.AddElement((XmlSchemaElement)xsobj)); case "XmlSchemaSequence": return(this.AddSequence((XmlSchemaSequence)xsobj)); case "XmlSchemaChoice": return(this.AddChoice((XmlSchemaChoice)xsobj)); case "XmlSchemaAll": return(this.AddAll((XmlSchemaAll)xsobj)); case "XmlSchemaAny": return(this.AddAny((XmlSchemaAny)xsobj)); case "EmptyParticle": return(this.AddEmpty()); } throw new InvalidOperationException("Should not occur."); }
internal XmlSchemaObject AddItem(XmlSchemaObject item, XmlQualifiedName qname, XmlSchemas schemas) { if (item == null) { return(null); } if ((qname == null) || qname.IsEmpty) { return(null); } string str = item.GetType().Name + ":" + qname.ToString(); ArrayList list = (ArrayList)this.ObjectCache[str]; if (list == null) { list = new ArrayList(); this.ObjectCache[str] = list; } for (int i = 0; i < list.Count; i++) { XmlSchemaObject obj2 = (XmlSchemaObject)list[i]; if (obj2 == item) { return(obj2); } if (this.Match(obj2, item, true)) { return(obj2); } this.Warnings.Add(Res.GetString("XmlMismatchSchemaObjects", new object[] { item.GetType().Name, qname.Name, qname.Namespace })); this.Warnings.Add("DEBUG:Cached item key:\r\n" + ((string)this.looks[obj2]) + "\r\nnew item key:\r\n" + ((string)this.looks[item])); } list.Add(item); return(item); }
internal bool Match(XmlSchemaObject o1, XmlSchemaObject o2, bool shareTypes) { if (o1 == o2) { return(true); } if (o1.GetType() != o2.GetType()) { return(false); } if (Hash[o1] == null) { Hash[o1] = GetHash(o1); } int hash1 = (int)Hash[o1]; int hash2 = GetHash(o2); if (hash1 != hash2) { return(false); } if (shareTypes) { return(CompositeHash(o1, hash1) == CompositeHash(o2, hash2)); } return(true); }
/// <summary> /// Placeholder /// </summary> public static string GetName(this XmlSchemaObject item) { switch (item) { case XmlSchemaElement x: return(x.Name); case XmlSchemaAttribute x: return(x.Name); case XmlSchemaComplexType x: return(x.Name); case XmlSchemaSimpleType x: return(x.Name); case XmlSchemaGroup x: return(x.Name); case XmlSchemaAttributeGroup x: return(x.Name); default: throw new ArgumentException($"Item of type '{item.GetType().Name}' cannot have a name"); } }
internal bool Match(XmlSchemaObject o1, XmlSchemaObject o2, bool shareTypes) { if (o1 != o2) { if (o1.GetType() != o2.GetType()) { return(false); } if (this.Hash[o1] == null) { this.Hash[o1] = this.GetHash(o1); } int hash = (int)this.Hash[o1]; int num2 = this.GetHash(o2); if (hash != num2) { return(false); } if (shareTypes) { return(this.CompositeHash(o1, hash) == this.CompositeHash(o2, num2)); } } return(true); }
internal object Find(XmlQualifiedName name, Type type, bool checkCache) { if (!this.IsCompiled) { foreach (System.Xml.Schema.XmlSchema schema in base.List) { Preprocess(schema); } } IList list = (IList)this.SchemaSet.Schemas(name.Namespace); if (list != null) { foreach (System.Xml.Schema.XmlSchema schema2 in list) { Preprocess(schema2); XmlSchemaObject obj2 = null; if (typeof(XmlSchemaType).IsAssignableFrom(type)) { obj2 = schema2.SchemaTypes[name]; if ((obj2 != null) && type.IsAssignableFrom(obj2.GetType())) { goto Label_0169; } continue; } if (type == typeof(XmlSchemaGroup)) { obj2 = schema2.Groups[name]; } else if (type == typeof(XmlSchemaAttributeGroup)) { obj2 = schema2.AttributeGroups[name]; } else if (type == typeof(XmlSchemaElement)) { obj2 = schema2.Elements[name]; } else if (type == typeof(XmlSchemaAttribute)) { obj2 = schema2.Attributes[name]; } else if (type == typeof(XmlSchemaNotation)) { obj2 = schema2.Notations[name]; } Label_0169: if (((obj2 != null) && this.shareTypes) && (checkCache && !this.IsReference(obj2))) { obj2 = this.Cache.AddItem(obj2, name, this); } if (obj2 != null) { return(obj2); } } } return(null); }
internal XmlSchemaObject AddItem(XmlSchemaObject item, XmlQualifiedName qname, XmlSchemas schemas) { if (item == null) { return(null); } if (qname == null || qname.IsEmpty) { return(null); } string key = item.GetType().Name + ":" + qname.ToString(); ArrayList list = (ArrayList)ObjectCache[key]; if (list == null) { list = new ArrayList(); ObjectCache[key] = list; } for (int i = 0; i < list.Count; i++) { XmlSchemaObject cachedItem = (XmlSchemaObject)list[i]; if (cachedItem == item) { return(cachedItem); } if (Match(cachedItem, item, true)) { return(cachedItem); } else { Warnings.Add(Res.GetString(Res.XmlMismatchSchemaObjects, item.GetType().Name, qname.Name, qname.Namespace)); Warnings.Add("DEBUG:Cached item key:\r\n" + (string)looks[cachedItem] + "\r\nnew item key:\r\n" + (string)looks[item]); } } // no match found we need to insert the new type in the cache list.Add(item); return(item); }
private void FillXsltArgumentList(XsltArgumentList argumentList, string prefix, XmlSchemaObject obj) { var topic = (obj == null) ? null : Context.TopicManager.GetTopic(obj); var itemType = (obj == null) ? String.Empty : obj.GetType().Name.Substring(9).ToLower(); var itemNamespace = (obj == null) ? String.Empty : obj.GetSchema().TargetNamespace ?? String.Empty; var itemUri = (topic == null) ? String.Empty : topic.LinkUri; argumentList.AddParam(prefix + "ItemType", String.Empty, itemType); argumentList.AddParam(prefix + "ItemNamespace", String.Empty, itemNamespace); argumentList.AddParam(prefix + "ItemUri", String.Empty, itemUri); }
private static string Dump(XmlSchemaObject o) { XmlWriterSettings settings = new XmlWriterSettings { OmitXmlDeclaration = true, Indent = true }; XmlSerializer serializer = new XmlSerializer(o.GetType()); StringWriter output = new StringWriter(CultureInfo.InvariantCulture); XmlWriter xmlWriter = XmlWriter.Create(output, settings); XmlSerializerNamespaces namespaces = new XmlSerializerNamespaces(); namespaces.Add("xs", "http://www.w3.org/2001/XMLSchema"); serializer.Serialize(xmlWriter, o, namespaces); return(output.ToString()); }
private static string Dump(XmlSchemaObject o) { XmlWriterSettings settings = new XmlWriterSettings(); settings.OmitXmlDeclaration = true; settings.Indent = true; XmlSerializer s = new XmlSerializer(o.GetType()); StringWriter sw = new StringWriter(CultureInfo.InvariantCulture); XmlWriter xmlWriter = XmlWriter.Create(sw, settings); XmlSerializerNamespaces ns = new XmlSerializerNamespaces(); ns.Add("xs", XmlSchema.Namespace); s.Serialize(xmlWriter, o, ns); return(sw.ToString()); }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="xmlSchemaObject"></param> /// <returns></returns> private XmlSchemaComplexType findParentElement(XmlSchemaObject xmlSchemaObject) { if (!xmlSchemaObject.GetType().Equals(typeof(XmlSchemaComplexType))) { if (xmlSchemaObject.Parent != null) { return(findParentElement(xmlSchemaObject.Parent)); } else { return((XmlSchemaComplexType)xmlSchemaObject); } } else { return((XmlSchemaComplexType)xmlSchemaObject); } }
/// <summary> /// Using reflection, retrieves the value for any property that is named 'Name'. /// </summary> /// <param name="object"></param> /// <returns></returns> public static string GetPotentialName(this XmlSchemaObject @object) { var properties = @object.GetType().GetProperties(); var possibleNameProp = properties.FirstOrDefault(p => p.Name == "Name"); if (possibleNameProp == null) { return(null); } var possibleNameValue = possibleNameProp.GetValue(@object); if (!(possibleNameValue is string)) { throw new NotSupportedException("Bad type!"); } return(Convert.ToString(possibleNameValue)); }
internal XmlSchemaObject Find(XmlSchemaObject o, IList originals) { string str = ItemName(o); if (str != null) { Type type = o.GetType(); foreach (System.Xml.Schema.XmlSchema schema in originals) { foreach (XmlSchemaObject obj2 in schema.Items) { if ((obj2.GetType() == type) && (str == ItemName(obj2))) { return(obj2); } } } } return(null); }
static void InvokeHandler(XmlSchemaObject schemaObject, HelpExampleGeneratorContext context) { if (++context.currentDepthLevel < MaxDepthLevel) { Action <XmlSchemaObject, HelpExampleGeneratorContext> action; Type objectType = schemaObject.GetType(); if (context.objectHandler.TryGetValue(objectType, out action)) { action(schemaObject, context); } else if (objectType.Name != "EmptyParticle") { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.HelpExampleGeneratorHandlerNotFound, schemaObject.GetType().Name))); } --context.currentDepthLevel; } else { throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new InvalidOperationException(SR2.GetString(SR2.HelpExampleGeneratorMaxDepthLevelReached, schemaObject.GetType().Name))); } }
static void InvokeHandler(XmlSchemaObject schemaObject, HelpExampleGeneratorContext context) { if (++context.currentDepthLevel < MaxDepthLevel) { Action <XmlSchemaObject, HelpExampleGeneratorContext> action; Type objectType = schemaObject.GetType(); if (context.objectHandler.TryGetValue(objectType, out action)) { action(schemaObject, context); } else if (objectType.Name != "EmptyParticle") { throw new InvalidOperationException(String.Format("Handler for type {0} not found.", schemaObject.GetType().Name)); } --context.currentDepthLevel; } else { throw new InvalidOperationException(String.Format("Max depth level reached at {0}.", schemaObject.GetType().Name)); } }
/// <summary> /// Get Name of a top level schema item /// </summary> /// <param name="item"></param> /// <return></return> /// <remarks></remarks> private static string GetSchemaItemName(XmlSchemaObject item) { if (item == null) { throw new ArgumentNullException("item"); } Type itemType = item.GetType(); PropertyInfo nameProperty = itemType.GetProperty("Name"); if (nameProperty != null) { object nameValue = nameProperty.GetValue(item, new object[] { }); if (nameValue is string) { return((string)nameValue); } return(String.Empty); } return(String.Empty); }
void Parse_AnyObject(TreeNode inner, XmlSchemaObject obj) { Type type = obj.GetType(); PropertyInfo[] properties = type.GetProperties(); foreach (PropertyInfo property in properties) { if (property.PropertyType.FullName.Equals(SOMListName)) { XmlSchemaCollection somList = property.GetValue(obj, null) as XmlSchemaCollection; if (somList != null) { foreach (XmlSchemaObject somObj in somList) { Parse_AnyObject(inner, somObj); } } } } }
internal XmlSchemaObject Find(XmlSchemaObject o, IList originals) { string name = ItemName(o); if (name == null) { return(null); } Type type = o.GetType(); foreach (XmlSchema s in originals) { foreach (XmlSchemaObject item in s.Items) { if (item.GetType() == type && name == ItemName(item)) { return(item); } } } return(null); }
/// <summary> /// Compare two schema objects /// </summary> /// <return></return> /// <remarks> /// For all those functions, we follow the same pattern: /// return false: find not-ignorable difference between them. differentLocation will contain the path /// return true, with empty differentLocation -- no difference found /// return true, with non-empty differentLocation -- ignorable difference found under that location /// </remarks> private static bool AreSchemaObjectsEquivalent(XmlSchemaObject originalItem, XmlSchemaObject item, out string differentLocation) { differentLocation = String.Empty; Type itemType = originalItem.GetType(); if (itemType != item.GetType()) { return(false); } string ignorableDifferenceLocation = String.Empty; PropertyInfo[] properties = itemType.GetProperties(); foreach (PropertyInfo property in properties) { if (IsPersistedProperty(property)) { bool ignorableProperty = ShouldIgnoreSchemaProperty(property); object originalValue = property.GetValue(originalItem, new object[] { }); object newValue = property.GetValue(item, new object[] { }); if (!CompareSchemaPropertyValues(property, originalValue, newValue, out differentLocation) && !ignorableProperty) { return(false); } if (String.IsNullOrEmpty(ignorableDifferenceLocation)) { ignorableDifferenceLocation = differentLocation; } } } differentLocation = ignorableDifferenceLocation; return(true); }
private static XmlSchemaType GetXsdTypeForXsdObject(XmlSchemaObject sourceXsdObject) { if (sourceXsdObject is XmlSchemaElement) { return(((XmlSchemaElement)sourceXsdObject).ElementSchemaType); } if (sourceXsdObject is XmlSchemaAttribute) { return(((XmlSchemaAttribute)sourceXsdObject).AttributeSchemaType); } throw new ArgumentException("Source XSD Object is neither an XSD Element nor an XSD Attribute. The type of the XSD Object is " + sourceXsdObject.GetType()); }
public static List <XmlSchemaElement> GetAllElements(XmlSchemaObject obj, bool recursive, List <XmlSchemaElement> allElements) { List <XmlSchemaElement> elements = new List <XmlSchemaElement>(); // Element if (obj.GetType().Equals(typeof(XmlSchemaElement))) { XmlSchemaElement element = (XmlSchemaElement)obj; XmlSchemaComplexType complexType = element.ElementSchemaType as XmlSchemaComplexType; if (complexType != null) { #region sequence /// Get the sequence particle of the complex type. XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence; if (sequence != null) { // Iterate over each XmlSchemaElement in the Items collection. foreach (XmlSchemaObject childElement in sequence.Items) { elements = GetElements(childElement, elements, recursive, allElements); } } #endregion #region sequence /// Get the sequence particle of the complex type. XmlSchemaAll all = complexType.ContentTypeParticle as XmlSchemaAll; if (all != null) { // Iterate over each XmlSchemaElement in the Items collection. foreach (XmlSchemaObject childElement in all.Items) { elements = GetElements(childElement, elements, recursive, allElements); } } #endregion #region choice // check if it is e choice XmlSchemaChoice choice = complexType.ContentTypeParticle as XmlSchemaChoice; if (choice != null) { // Iterate over each XmlSchemaElement in the Items collection. foreach (XmlSchemaObject childElement in choice.Items) { elements = GetElements(childElement, elements, recursive, allElements); } } #endregion } } if (obj.GetType().Equals(typeof(XmlSchemaComplexType))) { XmlSchemaComplexType complexType = obj as XmlSchemaComplexType; if (complexType != null) { #region sequence /// Get the sequence particle of the complex type. XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence; if (sequence != null) { // Iterate over each XmlSchemaElement in the Items collection. foreach (XmlSchemaObject childElement in sequence.Items) { elements = GetElements(childElement, elements, recursive, allElements); } } #endregion #region choice // check if it is e choice XmlSchemaChoice choice = complexType.ContentTypeParticle as XmlSchemaChoice; if (choice != null) { // Iterate over each XmlSchemaElement in the Items collection. foreach (XmlSchemaObject childElement in choice.Items) { elements = GetElements(childElement, elements, recursive, allElements); } } #endregion } } if (obj is XmlSchemaGroup) { XmlSchemaGroup group = obj as XmlSchemaGroup; #region sequence /// Get the sequence particle of the complex type. XmlSchemaSequence sequence = group.Particle as XmlSchemaSequence; if (sequence != null) { // Iterate over each XmlSchemaElement in the Items collection. foreach (XmlSchemaObject childElement in sequence.Items) { elements = GetElements(childElement, elements, recursive, allElements); } } #endregion #region choice // check if it is e choice XmlSchemaChoice choice = group.Particle as XmlSchemaChoice; if (choice != null) { // Iterate over each XmlSchemaElement in the Items collection. foreach (XmlSchemaObject childElement in choice.Items) { elements = GetElements(childElement, elements, recursive, allElements); } } #endregion } //if (obj is XmlSchemaSequence) //{ // // Iterate over each XmlSchemaElement in the Items collection. // foreach (XmlSchemaObject childElement in ((XmlSchemaSequence)obj).Items) // { // elements = GetAllElements(childElement, recursive, allElements); // } //} //if (obj is XmlSchemaChoice) //{ // // Iterate over each XmlSchemaElement in the Items collection. // foreach (XmlSchemaObject childElement in ((XmlSchemaChoice)obj).Items) // { // elements = GetAllElements(childElement, recursive, allElements); // } //} return(elements); }
private static string GetSchemaItem(XmlSchemaObject o, string ns, string details) { if (o == null) { return(null); } while (o.Parent != null && !(o.Parent is XmlSchema)) { o = o.Parent; } if (ns == null || ns.Length == 0) { XmlSchemaObject tmp = o; while (tmp.Parent != null) { tmp = tmp.Parent; } if (tmp is XmlSchema) { ns = ((XmlSchema)tmp).TargetNamespace; } } string item = null; if (o is XmlSchemaNotation) { item = SR.Format(SR.XmlSchemaNamedItem, ns, "notation", ((XmlSchemaNotation)o).Name, details); } else if (o is XmlSchemaGroup) { item = SR.Format(SR.XmlSchemaNamedItem, ns, "group", ((XmlSchemaGroup)o).Name, details); } else if (o is XmlSchemaElement) { XmlSchemaElement e = ((XmlSchemaElement)o); if (e.Name == null || e.Name.Length == 0) { XmlQualifiedName parentName = XmlSchemas.GetParentName(o); // Element reference '{0}' declared in schema type '{1}' from namespace '{2}' item = SR.Format(SR.XmlSchemaElementReference, e.RefName.ToString(), parentName.Name, parentName.Namespace); } else { item = SR.Format(SR.XmlSchemaNamedItem, ns, "element", e.Name, details); } } else if (o is XmlSchemaType) { item = SR.Format(SR.XmlSchemaNamedItem, ns, o.GetType() == typeof(XmlSchemaSimpleType) ? "simpleType" : "complexType", ((XmlSchemaType)o).Name, null); } else if (o is XmlSchemaAttributeGroup) { item = SR.Format(SR.XmlSchemaNamedItem, ns, "attributeGroup", ((XmlSchemaAttributeGroup)o).Name, details); } else if (o is XmlSchemaAttribute) { XmlSchemaAttribute a = ((XmlSchemaAttribute)o); if (a.Name == null || a.Name.Length == 0) { XmlQualifiedName parentName = XmlSchemas.GetParentName(o); // Attribure reference '{0}' declared in schema type '{1}' from namespace '{2}' return(SR.Format(SR.XmlSchemaAttributeReference, a.RefName.ToString(), parentName.Name, parentName.Namespace)); } else { item = SR.Format(SR.XmlSchemaNamedItem, ns, "attribute", a.Name, details); } } else if (o is XmlSchemaContent) { XmlQualifiedName parentName = XmlSchemas.GetParentName(o); // Check content definition of schema type '{0}' from namespace '{1}'. {2} item = SR.Format(SR.XmlSchemaContentDef, parentName.Name, parentName.Namespace, null); } else if (o is XmlSchemaExternal) { string itemType = o is XmlSchemaImport ? "import" : o is XmlSchemaInclude ? "include" : o is XmlSchemaRedefine ? "redefine" : o.GetType().Name; item = SR.Format(SR.XmlSchemaItem, ns, itemType, details); } else if (o is XmlSchema) { item = SR.Format(SR.XmlSchema, ns, details); } else { item = SR.Format(SR.XmlSchemaNamedItem, ns, o.GetType().Name, null, details); } return(item); }
internal object Find(XmlQualifiedName name, Type type, bool checkCache) { if (!IsCompiled) { foreach (XmlSchema schema in List) { Preprocess(schema); } } IList values = (IList)SchemaSet.Schemas(name.Namespace); if (values == null) { return(null); } foreach (XmlSchema schema in values) { Preprocess(schema); XmlSchemaObject ret = null; if (typeof(XmlSchemaType).IsAssignableFrom(type)) { ret = schema.SchemaTypes[name]; if (ret == null || !type.IsAssignableFrom(ret.GetType())) { continue; } } else if (type == typeof(XmlSchemaGroup)) { ret = schema.Groups[name]; } else if (type == typeof(XmlSchemaAttributeGroup)) { ret = schema.AttributeGroups[name]; } else if (type == typeof(XmlSchemaElement)) { ret = schema.Elements[name]; } else if (type == typeof(XmlSchemaAttribute)) { ret = schema.Attributes[name]; } else if (type == typeof(XmlSchemaNotation)) { ret = schema.Notations[name]; } #if DEBUG else { // use exception in the place of Debug.Assert to avoid throwing asserts from a server process such as aspnet_ewp.exe throw new InvalidOperationException(SR.Format(SR.XmlInternalErrorDetails, "XmlSchemas.Find: Invalid object type " + type.FullName)); } #endif if (ret != null && _shareTypes && checkCache && !IsReference(ret)) { ret = Cache.AddItem(ret, name, this); } if (ret != null) { return(ret); } } return(null); }
void Write3_XmlSchemaObject(XmlSchemaObject o) { if ((object)o == null) { return; } System.Type t = o.GetType(); if (t == typeof(XmlSchemaComplexType)) { Write35_XmlSchemaComplexType((XmlSchemaComplexType)o); return; } else if (t == typeof(XmlSchemaSimpleType)) { Write9_XmlSchemaSimpleType((XmlSchemaSimpleType)o); return; } else if (t == typeof(XmlSchemaElement)) { Write46_XmlSchemaElement((XmlSchemaElement)o); return; } else if (t == typeof(XmlSchemaAppInfo)) { Write7_XmlSchemaAppInfo((XmlSchemaAppInfo)o); return; } else if (t == typeof(XmlSchemaDocumentation)) { Write6_XmlSchemaDocumentation((XmlSchemaDocumentation)o); return; } else if (t == typeof(XmlSchemaAnnotation)) { Write5_XmlSchemaAnnotation((XmlSchemaAnnotation)o); return; } else if (t == typeof(XmlSchemaGroup)) { Write57_XmlSchemaGroup((XmlSchemaGroup)o); return; } else if (t == typeof(XmlSchemaXPath)) { Write49_XmlSchemaXPath("xpath", "", (XmlSchemaXPath)o); return; } else if (t == typeof(XmlSchemaIdentityConstraint)) { Write48_XmlSchemaIdentityConstraint((XmlSchemaIdentityConstraint)o); return; } else if (t == typeof(XmlSchemaUnique)) { Write51_XmlSchemaUnique((XmlSchemaUnique)o); return; } else if (t == typeof(XmlSchemaKeyref)) { Write50_XmlSchemaKeyref((XmlSchemaKeyref)o); return; } else if (t == typeof(XmlSchemaKey)) { Write47_XmlSchemaKey((XmlSchemaKey)o); return; } else if (t == typeof(XmlSchemaGroupRef)) { Write55_XmlSchemaGroupRef((XmlSchemaGroupRef)o); return; } else if (t == typeof(XmlSchemaAny)) { Write53_XmlSchemaAny((XmlSchemaAny)o); return; } else if (t == typeof(XmlSchemaSequence)) { Write54_XmlSchemaSequence((XmlSchemaSequence)o); return; } else if (t == typeof(XmlSchemaChoice)) { Write52_XmlSchemaChoice((XmlSchemaChoice)o); return; } else if (t == typeof(XmlSchemaAll)) { Write43_XmlSchemaAll((XmlSchemaAll)o); return; } else if (t == typeof(XmlSchemaComplexContentRestriction)) { Write56_XmlSchemaComplexContentRestriction((XmlSchemaComplexContentRestriction)o); return; } else if (t == typeof(XmlSchemaComplexContentExtension)) { Write42_XmlSchemaComplexContentExtension((XmlSchemaComplexContentExtension)o); return; } else if (t == typeof(XmlSchemaSimpleContentRestriction)) { Write40_XmlSchemaSimpleContentRestriction((XmlSchemaSimpleContentRestriction)o); return; } else if (t == typeof(XmlSchemaSimpleContentExtension)) { Write38_XmlSchemaSimpleContentExtension((XmlSchemaSimpleContentExtension)o); return; } else if (t == typeof(XmlSchemaComplexContent)) { Write41_XmlSchemaComplexContent((XmlSchemaComplexContent)o); return; } else if (t == typeof(XmlSchemaSimpleContent)) { Write36_XmlSchemaSimpleContent((XmlSchemaSimpleContent)o); return; } else if (t == typeof(XmlSchemaAnyAttribute)) { Write33_XmlSchemaAnyAttribute((XmlSchemaAnyAttribute)o); return; } else if (t == typeof(XmlSchemaAttributeGroupRef)) { Write32_XmlSchemaAttributeGroupRef((XmlSchemaAttributeGroupRef)o); return; } else if (t == typeof(XmlSchemaAttributeGroup)) { Write31_XmlSchemaAttributeGroup((XmlSchemaAttributeGroup)o); return; } else if (t == typeof(XmlSchemaSimpleTypeRestriction)) { Write15_XmlSchemaSimpleTypeRestriction((XmlSchemaSimpleTypeRestriction)o); return; } else if (t == typeof(XmlSchemaSimpleTypeList)) { Write14_XmlSchemaSimpleTypeList((XmlSchemaSimpleTypeList)o); return; } else if (t == typeof(XmlSchemaSimpleTypeUnion)) { Write12_XmlSchemaSimpleTypeUnion((XmlSchemaSimpleTypeUnion)o); return; } else if (t == typeof(XmlSchemaAttribute)) { Write1_XmlSchemaAttribute((XmlSchemaAttribute)o); return; } }
private static List <XmlSchemaElement> GetElements(XmlSchemaObject element, List <XmlSchemaElement> list, bool recursive, List <XmlSchemaElement> allElements) { // Element if (element.GetType().Equals(typeof(XmlSchemaElement))) { XmlSchemaElement child = (XmlSchemaElement)element; if (child.Name != null) { if (list.Where(e => e.Name.Equals(child.Name)).Count() == 0) { //if (!child.SchemaTypeName.Name.Equals(parentTypeName)) //{ list.Add(child); if (recursive) { Debug.WriteLine("--<" + child.Name); XmlSchemaComplexType complexType = child.ElementSchemaType as XmlSchemaComplexType; if (complexType != null) { #region sequence /// Get the sequence particle of the complex type. XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence; if (sequence != null) { // Iterate over each XmlSchemaElement in the Items collection. foreach (XmlSchemaObject childElement in sequence.Items) { list = GetElements(childElement, list, recursive, allElements); } } #endregion #region choice // check if it is e choice XmlSchemaChoice choice = complexType.ContentTypeParticle as XmlSchemaChoice; if (choice != null) { // Iterate over each XmlSchemaElement in the Items collection. foreach (XmlSchemaObject childElement in choice.Items) { list = GetElements(childElement, list, recursive, allElements); } } #endregion } } //} } } else { if (child.RefName != null) { XmlSchemaElement refElement = allElements.Where(e => e.QualifiedName.Equals(child.RefName)).FirstOrDefault(); if (refElement != null) { //set parameters from the child to the refernce refElement.MinOccurs = child.MinOccurs; refElement.MaxOccurs = child.MaxOccurs; list.Add(refElement); if (recursive) { Debug.WriteLine("--<" + refElement.Name); XmlSchemaComplexType complexType = refElement.ElementSchemaType as XmlSchemaComplexType; if (complexType != null) { #region sequence /// Get the sequence particle of the complex type. XmlSchemaSequence sequence = complexType.ContentTypeParticle as XmlSchemaSequence; if (sequence != null) { // Iterate over each XmlSchemaElement in the Items collection. foreach (XmlSchemaObject childElement in sequence.Items) { list = GetElements(childElement, list, recursive, allElements); } } #endregion #region choice // check if it is e choice XmlSchemaChoice choice = complexType.ContentTypeParticle as XmlSchemaChoice; if (choice != null) { // Iterate over each XmlSchemaElement in the Items collection. foreach (XmlSchemaObject childElement in choice.Items) { list = GetElements(childElement, list, recursive, allElements); } } #endregion } } } } } } else if (element.GetType().Equals(typeof(XmlSchemaChoice))) { XmlSchemaChoice choice = (XmlSchemaChoice)element; // Iterate over each XmlSchemaElement in the Items collection. foreach (XmlSchemaObject childElement in choice.Items) { list = GetElements(childElement, list, recursive, allElements); } } else if (element.GetType().Equals(typeof(XmlSchemaSequence))) { XmlSchemaSequence sequence = (XmlSchemaSequence)element; // Iterate over each XmlSchemaElement in the Items collection. foreach (XmlSchemaObject childElement in sequence.Items) { list = GetElements(childElement, list, recursive, allElements); } } return(list); }
internal void Depends(XmlSchemaObject item, ArrayList refs) { if (item == null || scope[item] != null) { return; } Type t = item.GetType(); if (typeof(XmlSchemaType).IsAssignableFrom(t)) { XmlQualifiedName baseName = XmlQualifiedName.Empty; XmlSchemaType baseType = null; XmlSchemaParticle particle = null; XmlSchemaObjectCollection attributes = null; if (item is XmlSchemaComplexType) { XmlSchemaComplexType ct = (XmlSchemaComplexType)item; if (ct.ContentModel != null) { XmlSchemaContent content = ct.ContentModel.Content; if (content is XmlSchemaComplexContentRestriction) { baseName = ((XmlSchemaComplexContentRestriction)content).BaseTypeName; attributes = ((XmlSchemaComplexContentRestriction)content).Attributes; } else if (content is XmlSchemaSimpleContentRestriction) { XmlSchemaSimpleContentRestriction restriction = (XmlSchemaSimpleContentRestriction)content; if (restriction.BaseType != null) { baseType = restriction.BaseType; } else { baseName = restriction.BaseTypeName; } attributes = restriction.Attributes; } else if (content is XmlSchemaComplexContentExtension) { XmlSchemaComplexContentExtension extension = (XmlSchemaComplexContentExtension)content; attributes = extension.Attributes; particle = extension.Particle; baseName = extension.BaseTypeName; } else if (content is XmlSchemaSimpleContentExtension) { XmlSchemaSimpleContentExtension extension = (XmlSchemaSimpleContentExtension)content; attributes = extension.Attributes; baseName = extension.BaseTypeName; } } else { attributes = ct.Attributes; particle = ct.Particle; } if (particle is XmlSchemaGroupRef) { XmlSchemaGroupRef refGroup = (XmlSchemaGroupRef)particle; particle = ((XmlSchemaGroup)schemas.Find(refGroup.RefName, typeof(XmlSchemaGroup), false)).Particle; } else if (particle is XmlSchemaGroupBase) { particle = (XmlSchemaGroupBase)particle; } } else if (item is XmlSchemaSimpleType) { XmlSchemaSimpleType simpleType = (XmlSchemaSimpleType)item; XmlSchemaSimpleTypeContent content = simpleType.Content; if (content is XmlSchemaSimpleTypeRestriction) { baseType = ((XmlSchemaSimpleTypeRestriction)content).BaseType; baseName = ((XmlSchemaSimpleTypeRestriction)content).BaseTypeName; } else if (content is XmlSchemaSimpleTypeList) { XmlSchemaSimpleTypeList list = (XmlSchemaSimpleTypeList)content; if (list.ItemTypeName != null && !list.ItemTypeName.IsEmpty) { baseName = list.ItemTypeName; } if (list.ItemType != null) { baseType = list.ItemType; } } else if (content is XmlSchemaSimpleTypeRestriction) { baseName = ((XmlSchemaSimpleTypeRestriction)content).BaseTypeName; } else if (t == typeof(XmlSchemaSimpleTypeUnion)) { XmlQualifiedName[] memberTypes = ((XmlSchemaSimpleTypeUnion)item).MemberTypes; if (memberTypes != null) { for (int i = 0; i < memberTypes.Length; i++) { XmlSchemaType type = (XmlSchemaType)schemas.Find(memberTypes[i], typeof(XmlSchemaType), false); AddRef(refs, type); } } } } if (baseType == null && !baseName.IsEmpty && baseName.Namespace != XmlSchema.Namespace) { baseType = (XmlSchemaType)schemas.Find(baseName, typeof(XmlSchemaType), false); } if (baseType != null) { AddRef(refs, baseType); } if (particle != null) { Depends(particle, refs); } if (attributes != null) { for (int i = 0; i < attributes.Count; i++) { Depends(attributes[i], refs); } } } else if (t == typeof(XmlSchemaElement)) { XmlSchemaElement el = (XmlSchemaElement)item; if (!el.SubstitutionGroup.IsEmpty) { if (el.SubstitutionGroup.Namespace != XmlSchema.Namespace) { XmlSchemaElement head = (XmlSchemaElement)schemas.Find(el.SubstitutionGroup, typeof(XmlSchemaElement), false); AddRef(refs, head); } } if (!el.RefName.IsEmpty) { el = (XmlSchemaElement)schemas.Find(el.RefName, typeof(XmlSchemaElement), false); AddRef(refs, el); } else if (!el.SchemaTypeName.IsEmpty) { XmlSchemaType type = (XmlSchemaType)schemas.Find(el.SchemaTypeName, typeof(XmlSchemaType), false); AddRef(refs, type); } else { Depends(el.SchemaType, refs); } } else if (t == typeof(XmlSchemaGroup)) { Depends(((XmlSchemaGroup)item).Particle); } else if (t == typeof(XmlSchemaGroupRef)) { XmlSchemaGroup group = (XmlSchemaGroup)schemas.Find(((XmlSchemaGroupRef)item).RefName, typeof(XmlSchemaGroup), false); AddRef(refs, group); } else if (typeof(XmlSchemaGroupBase).IsAssignableFrom(t)) { foreach (XmlSchemaObject o in ((XmlSchemaGroupBase)item).Items) { Depends(o, refs); } } else if (t == typeof(XmlSchemaAttributeGroupRef)) { XmlSchemaAttributeGroup group = (XmlSchemaAttributeGroup)schemas.Find(((XmlSchemaAttributeGroupRef)item).RefName, typeof(XmlSchemaAttributeGroup), false); AddRef(refs, group); } else if (t == typeof(XmlSchemaAttributeGroup)) { foreach (XmlSchemaObject o in ((XmlSchemaAttributeGroup)item).Attributes) { Depends(o, refs); } } else if (t == typeof(XmlSchemaAttribute)) { XmlSchemaAttribute at = (XmlSchemaAttribute)item; if (!at.RefName.IsEmpty) { at = (XmlSchemaAttribute)schemas.Find(at.RefName, typeof(XmlSchemaAttribute), false); AddRef(refs, at); } else if (!at.SchemaTypeName.IsEmpty) { XmlSchemaType type = (XmlSchemaType)schemas.Find(at.SchemaTypeName, typeof(XmlSchemaType), false); AddRef(refs, type); } else { Depends(at.SchemaType, refs); } } if (typeof(XmlSchemaAnnotated).IsAssignableFrom(t)) { XmlAttribute[] attrs = (XmlAttribute[])((XmlSchemaAnnotated)item).UnhandledAttributes; if (attrs != null) { for (int i = 0; i < attrs.Length; i++) { XmlAttribute attribute = attrs[i]; if (attribute.LocalName == Wsdl.ArrayType && attribute.NamespaceURI == Wsdl.Namespace) { string dims; XmlQualifiedName qname = TypeScope.ParseWsdlArrayType(attribute.Value, out dims, item); XmlSchemaType type = (XmlSchemaType)schemas.Find(qname, typeof(XmlSchemaType), false); AddRef(refs, type); } } } } }
private SourceItem CreateSourceItemTree(Entry mapForceEntry, XmlSchemaObject sourceXsdObject) { XmlSchemaType xsdType = GetXsdTypeForXsdObject(sourceXsdObject); var sourceItem = new SourceItem(mapForceEntry.Name, xsdType, mapForceEntry.XsdObjectType, mapForceMapping.GetMappingTargetKey(mapForceEntry.InputOutputKey.Value)); IEnumerable <XmlSchemaObject> childrenOfXsdType = GetChildElementsAndAttributesDefinedByXsdType(sourceItem.XsdType); //HashSet<string> childrenOfXsdTypeNames = new HashSet<string>(); //int unknownChildTypeCount = 0; //foreach (XmlSchemaObject xmlSchemaObject in childrenOfXsdType) //{ // if (xmlSchemaObject is XmlSchemaElement) // { // childrenOfXsdTypeNames.Add("E_" + ((XmlSchemaElement)xmlSchemaObject).QualifiedName.Name); // } // else if (xmlSchemaObject is XmlSchemaAttribute) // { // childrenOfXsdTypeNames.Add("A_" + ((XmlSchemaAttribute)xmlSchemaObject).QualifiedName.Name); // } // else // { // childrenOfXsdTypeNames.Add("Unknown Child Type["+(++unknownChildTypeCount)+"]: " + xmlSchemaObject.GetType().Name); // } //} //HashSet<string> childrenOfMapForceEntryNames = new HashSet<string>(); //foreach (Entry subEntry in mapForceEntry.SubEntries) //{ // switch (subEntry.XsdObjectType) // { // case XsdObjectType.Element: // childrenOfMapForceEntryNames.Add("E_" + subEntry.Name); // break; // case XsdObjectType.Attribute: // childrenOfMapForceEntryNames.Add("A_" + subEntry.Name); // break; // } //} //HashSet<string> mapForceEntriesNotFoundInXsd = new HashSet<string>(childrenOfMapForceEntryNames); //mapForceEntriesNotFoundInXsd.ExceptWith(childrenOfXsdTypeNames); //if (mapForceEntriesNotFoundInXsd.Count > 0) //{ // Console.Out.WriteLine("AAAHHHHHHHHH!!!!!!!!!!!!!!!!!!!!!!"); //} foreach (XmlSchemaObject childOfXsdType in childrenOfXsdType) { Entry mapForceSubEntry; if (childOfXsdType is XmlSchemaElement) { mapForceSubEntry = mapForceEntry.GetSubEntryForElement(((XmlSchemaElement)childOfXsdType).QualifiedName.Name); } else if (childOfXsdType is XmlSchemaAttribute) { mapForceSubEntry = mapForceEntry.GetSubEntryForAttribute(((XmlSchemaAttribute)childOfXsdType).QualifiedName.Name); } else { throw new Exception("Child of XSD Type is neither an XSD Element nor an XSD Attribute. The type of the Child is " + sourceXsdObject.GetType()); } if (mapForceSubEntry != null) { SourceItem sourceItemTreeForChild = CreateSourceItemTree(mapForceSubEntry, childOfXsdType); sourceItem.AddChild(sourceItemTreeForChild); } else { XmlSchemaType xsdTypeForChild = GetXsdTypeForXsdObject(childOfXsdType); if (childOfXsdType is XmlSchemaElement) { sourceItem.AddChild(new SourceItem(((XmlSchemaElement)childOfXsdType).QualifiedName.Name, xsdTypeForChild, XsdObjectType.Element, null)); } if (childOfXsdType is XmlSchemaAttribute) { sourceItem.AddChild(new SourceItem(((XmlSchemaAttribute)childOfXsdType).QualifiedName.Name, xsdTypeForChild, XsdObjectType.Attribute, null)); } } } return(sourceItem); }