/// <summary> /// Gets a value indicating whether the /// <see cref='QualifiedNameCollection'/> contains the specified <see cref='QualifiedName'/>. /// </summary> /// <param name='val'>The <see cref='QualifiedName'/> to locate.</param> /// <returns> /// <see langword='true'/> if the <see cref='QualifiedName'/> is contained in the collection; /// otherwise, <see langword='false'/>. /// </returns> /// <seealso cref='QualifiedNameCollection.IndexOf'/> public bool Contains(QualifiedName val) { return List.Contains(val); }
/// <summary> /// Copies the <see cref='QualifiedNameCollection'/> values to a one-dimensional <see cref='Array'/> instance at the /// specified index. /// </summary> /// <param name='array'>The one-dimensional <see cref='Array'/> that is the destination of the values copied from <see cref='QualifiedNameCollection'/>.</param> /// <param name='index'>The index in <paramref name='array'/> where copying begins.</param> /// <exception cref='ArgumentException'> /// <para><paramref name='array'/> is multidimensional.</para> /// <para>-or-</para> /// <para>The number of elements in the <see cref='QualifiedNameCollection'/> is greater than /// the available space between <paramref name='arrayIndex'/> and the end of /// <paramref name='array'/>.</para> /// </exception> /// <exception cref='ArgumentNullException'><paramref name='array'/> is <see langword='null'/>. </exception> /// <exception cref='ArgumentOutOfRangeException'><paramref name='arrayIndex'/> is less than <paramref name='array'/>'s lowbound. </exception> /// <seealso cref='Array'/> public void CopyTo(QualifiedName[] array, int index) { List.CopyTo(array, index); }
/// <summary> /// Adds a <see cref='QualifiedName'/> with the specified value to the /// <see cref='QualifiedNameCollection'/>. /// </summary> /// <param name='val'>The <see cref='QualifiedName'/> to add.</param> /// <returns>The index at which the new element was inserted.</returns> /// <seealso cref='QualifiedNameCollection.AddRange'/> public int Add(QualifiedName val) { return List.Add(val); }
/// <summary> /// Copies the elements of an array to the end of the <see cref='QualifiedNameCollection'/>. /// </summary> /// <param name='val'> /// An array of type <see cref='QualifiedName'/> containing the objects to add to the collection. /// </param> /// <seealso cref='QualifiedNameCollection.Add'/> public void AddRange(QualifiedName[] val) { for (int i = 0; i < val.Length; i++) { this.Add(val[i]); } }
/// <summary> /// Finds an element in the schema. /// </summary> /// <remarks> /// Only looks at the elements that are defined in the /// root of the schema so it will not find any elements /// that are defined inside any complex types. /// </remarks> public XmlSchemaElement FindElement(QualifiedName name) { foreach (XmlSchemaElement element in schema.Elements.Values) { if (name.Equals(element.QualifiedName)) { return element; } } return null; }
/// <summary> /// Initializes a new instance of <see cref='QualifiedNameCollection'/> containing any array of <see cref='QualifiedName'/> objects. /// </summary> /// <param name='val'> /// A array of <see cref='QualifiedName'/> objects with which to intialize the collection /// </param> public QualifiedNameCollection(QualifiedName[] val) { this.AddRange(val); }
XmlSchemaElement FindElement(XmlSchemaGroupRef groupRef, QualifiedName name) { XmlSchemaElement matchedElement = null; XmlSchemaGroup group = FindGroup(groupRef.RefName.Name); if (group != null) { XmlSchemaSequence sequence = group.Particle as XmlSchemaSequence; XmlSchemaChoice choice = group.Particle as XmlSchemaChoice; if (sequence != null) { matchedElement = FindElement(sequence.Items, name); } else if (choice != null) { matchedElement = FindElement(choice.Items, name); } } return matchedElement; }
/// <summary> /// Removes a specific <see cref='QualifiedName'/> from the <see cref='QualifiedNameCollection'/>. /// </summary> /// <param name='val'>The <see cref='QualifiedName'/> to remove from the <see cref='QualifiedNameCollection'/>.</param> /// <exception cref='ArgumentException'><paramref name='val'/> is not found in the Collection.</exception> public void Remove(QualifiedName val) { List.Remove(val); }
/// <summary> /// Finds the named child element contained in the restriction element. /// </summary> XmlSchemaElement FindChildElement(XmlSchemaComplexContentRestriction restriction, QualifiedName name) { XmlSchemaElement matchedElement = null; XmlSchemaSequence sequence = restriction.Particle as XmlSchemaSequence; XmlSchemaGroupRef groupRef = restriction.Particle as XmlSchemaGroupRef; if (sequence != null) { matchedElement = FindElement(sequence.Items, name); } else if (groupRef != null) { matchedElement = FindElement(groupRef, name); } return matchedElement; }
/// <summary> /// Finds the element in the collection of schema objects. /// </summary> XmlSchemaElement FindElement(XmlSchemaObjectCollection items, QualifiedName name) { XmlSchemaElement matchedElement = null; foreach (XmlSchemaObject schemaObject in items) { XmlSchemaElement element = schemaObject as XmlSchemaElement; XmlSchemaSequence sequence = schemaObject as XmlSchemaSequence; XmlSchemaChoice choice = schemaObject as XmlSchemaChoice; XmlSchemaGroupRef groupRef = schemaObject as XmlSchemaGroupRef; if (element != null) { if (element.Name != null) { if (name.Name == element.Name) { matchedElement = element; } } else if (element.RefName != null) { if (name.Name == element.RefName.Name) { matchedElement = FindElement(element.RefName); } else { // Abstract element? XmlSchemaElement abstractElement = FindElement(element.RefName); if (abstractElement != null && abstractElement.IsAbstract) { matchedElement = FindSubstitutionGroupElement(abstractElement.QualifiedName, name); } } } } else if (sequence != null) { matchedElement = FindElement(sequence.Items, name); } else if (choice != null) { matchedElement = FindElement(choice.Items, name); } else if (groupRef != null) { matchedElement = FindElement(groupRef, name); } // Did we find a match? if (matchedElement != null) { break; } } return matchedElement; }
/// <summary> /// Finds the named child element contained in the extension element. /// </summary> XmlSchemaElement FindChildElement(XmlSchemaComplexContentExtension extension, QualifiedName name) { XmlSchemaElement matchedElement = null; XmlSchemaComplexType complexType = FindNamedType(schema, extension.BaseTypeName); if (complexType != null) { matchedElement = FindChildElement(complexType, name); if (matchedElement == null) { XmlSchemaSequence sequence = extension.Particle as XmlSchemaSequence; XmlSchemaChoice choice = extension.Particle as XmlSchemaChoice; XmlSchemaGroupRef groupRef = extension.Particle as XmlSchemaGroupRef; if (sequence != null) { matchedElement = FindElement(sequence.Items, name); } else if (choice != null) { matchedElement = FindElement(choice.Items, name); } else if (groupRef != null) { matchedElement = FindElement(groupRef, name); } } } return matchedElement; }
XmlSchemaElement FindChildElement(XmlSchemaComplexType complexType, QualifiedName name) { XmlSchemaElement matchedElement = null; XmlSchemaSequence sequence = complexType.Particle as XmlSchemaSequence; XmlSchemaChoice choice = complexType.Particle as XmlSchemaChoice; XmlSchemaGroupRef groupRef = complexType.Particle as XmlSchemaGroupRef; XmlSchemaAll all = complexType.Particle as XmlSchemaAll; XmlSchemaComplexContent complexContent = complexType.ContentModel as XmlSchemaComplexContent; if (sequence != null) { matchedElement = FindElement(sequence.Items, name); } else if (choice != null) { matchedElement = FindElement(choice.Items, name); } else if (complexContent != null) { XmlSchemaComplexContentExtension extension = complexContent.Content as XmlSchemaComplexContentExtension; XmlSchemaComplexContentRestriction restriction = complexContent.Content as XmlSchemaComplexContentRestriction; if (extension != null) { matchedElement = FindChildElement(extension, name); } else if (restriction != null) { matchedElement = FindChildElement(restriction, name); } } else if (groupRef != null) { matchedElement = FindElement(groupRef, name); } else if (all != null) { matchedElement = FindElement(all.Items, name); } return matchedElement; }
/// <summary> /// Finds an element that matches the specified <paramref name="name"/> /// from the children of the given <paramref name="element"/>. /// </summary> XmlSchemaElement FindChildElement(XmlSchemaElement element, QualifiedName name) { XmlSchemaElement matchedElement = null; XmlSchemaComplexType complexType = GetElementAsComplexType(element); if (complexType != null) { matchedElement = FindChildElement(complexType, name); } return matchedElement; }
/// <summary> /// Returns the index of a <see cref='QualifiedName'/> in /// the <see cref='QualifiedNameCollection'/>. /// </summary> /// <param name='val'>The <see cref='QualifiedName'/> to locate.</param> /// <returns> /// The index of the <see cref='QualifiedName'/> of <paramref name='val'/> in the /// <see cref='QualifiedNameCollection'/>, if found; otherwise, -1. /// </returns> /// <seealso cref='QualifiedNameCollection.Contains'/> public int IndexOf(QualifiedName val) { return List.IndexOf(val); }
/// <summary> /// Looks for the substitution group element of the specified name. /// </summary> XmlSchemaElement FindSubstitutionGroupElement(XmlQualifiedName group, QualifiedName name) { XmlSchemaElement matchedElement = null; foreach (XmlSchemaElement element in schema.Elements.Values) { if (element.SubstitutionGroup == group) { if (element.Name != null) { if (element.Name == name.Name) { matchedElement = element; break; } } } } return matchedElement; }
/// <summary> /// Inserts a <see cref='QualifiedName'/> into the <see cref='QualifiedNameCollection'/> at the specified index. /// </summary> /// <param name='index'>The zero-based index where <paramref name='val'/> should be inserted.</param> /// <param name='val'>The <see cref='QualifiedName'/> to insert.</param> /// <seealso cref='QualifiedNameCollection.Add'/> public void Insert(int index, QualifiedName val) { List.Insert(index, val); }
/// <summary> /// Gets the element name from the element start tag string. /// </summary> /// <param name="xml">This string must start at the /// element we are interested in.</param> static QualifiedName GetElementName(string xml) { string name = String.Empty; // Find the end of the element name. xml = xml.Replace("\r\n", " "); int index = xml.IndexOf(' '); if (index > 0) { name = xml.Substring(1, index - 1); } else { name = xml.Substring(1); } QualifiedName qualifiedName = new QualifiedName(); int prefixIndex = name.IndexOf(':'); if (prefixIndex > 0) { qualifiedName.Prefix = name.Substring(0, prefixIndex); qualifiedName.Name = name.Substring(prefixIndex + 1); } else { qualifiedName.Name = name; } return qualifiedName; }
/// <summary> /// Gets the parent element path based on the index position. /// </summary> public static XmlElementPath GetParentElementPath(string xml) { XmlElementPath path = new XmlElementPath(); try { using (var reader = new StringReader(xml)) { using (var xmlReader = new XmlTextReader(reader)) { xmlReader.XmlResolver = null; while (xmlReader.Read()) { switch (xmlReader.NodeType) { case XmlNodeType.Element: if (!xmlReader.IsEmptyElement) { QualifiedName elementName = new QualifiedName(xmlReader.LocalName, xmlReader.NamespaceURI, xmlReader.Prefix); path.Elements.Add(elementName); } break; case XmlNodeType.EndElement: path.Elements.RemoveLast(); break; } } } } } catch (XmlException) { //MessageBox.Show(e.Message); } catch (WebException) { // Do nothing. } path.Compact(); return path; }
/// <summary> /// Finds the complex type with the specified name. /// </summary> public XmlSchemaComplexType FindComplexType(QualifiedName name) { XmlQualifiedName qualifiedName = new XmlQualifiedName(name.Name, name.Namespace); return FindNamedType(schema, qualifiedName); }