CustomXmlSchemaCollection class

A collection of strings that represent XML schemas that are associated with a custom XML part.

public class CustomXmlSchemaCollection : IEnumerable<string>


Name Description
Count { get; } Gets the number of elements contained in the collection.
Item { get; set; } Gets or sets the element at the specified index.


Name Description
Add(string) Adds an item to the collection.
Clear() Removes all elements from the collection.
Clone() Makes a deep clone of this object.
GetEnumerator() Returns an enumerator object that can be used to iterate over all items in the collection.
IndexOf(string) Returns the zero-based index of the specified value in the collection.
Remove(string) Removes the specified value from the collection.
RemoveAt(int) Removes a value at the specified index.


You do not create instances of this class. You access the collection of XML schemas of a custom XML part via the Schemas property.


Shows how to work with an XML schema collection.

Document doc = new Document();

string xmlPartId = Guid.NewGuid().ToString("B");
string xmlPartContent = "<root><text>Hello, World!</text></root>";
CustomXmlPart xmlPart = doc.CustomXmlParts.Add(xmlPartId, xmlPartContent);

// Add an XML schema association.

// Clone the custom XML part's XML schema association collection,
// and then add a couple of new schemas to the clone.
CustomXmlSchemaCollection schemas = xmlPart.Schemas.Clone();

Assert.AreEqual(3, schemas.Count);
Assert.AreEqual(2, schemas.IndexOf(""));

// Enumerate the schemas and print each element.
using (IEnumerator<string> enumerator = schemas.GetEnumerator())
    while (enumerator.MoveNext())

// Below are three ways of removing schemas from the collection.
// 1 -  Remove a schema by index:

// 2 -  Remove a schema by value:

// 3 -  Use the "Clear" method to empty the collection at once.

Assert.AreEqual(0, schemas.Count);

See Also