CustomXmlSchemaCollection class

CustomXmlSchemaCollection class

A collection of strings that represent XML schemas that are associated with a custom XML part. To learn more, visit the Structured Document Tags or Content Control documentation article.

Remarks

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

Indexers

NameDescription
__getitem__(index)Gets or sets the element at the specified index.

Properties

NameDescription
countGets the number of elements contained in the collection.

Methods

NameDescription
add(value)Adds an item to the collection.
clear()Removes all elements from the collection.
clone()Makes a deep clone of this object.
index_of(value)Returns the zero-based index of the specified value in the collection.
remove(name)Removes the specified value from the collection.
remove_at(index)Removes a value at the specified index.

Examples

Shows how to work with an XML schema collection.

doc = aw.Document()

xml_part_id = str(uuid.uuid4())
xml_part_content = "<root><text>Hello, World!</text></root>"
xml_part = doc.custom_xml_parts.add(xml_part_id, xml_part_content)

# Add an XML schema association.
xml_part.schemas.add("http://www.w3.org/2001/XMLSchema")

# Clone the custom XML part's XML schema association collection,
# and then add a couple of new schemas to the clone.
schemas = xml_part.schemas.clone()
schemas.add("http://www.w3.org/2001/XMLSchema-instance")
schemas.add("http://schemas.microsoft.com/office/2006/metadata/contentType")

self.assertEqual(3, schemas.count)
self.assertEqual(2, schemas.index_of("http://schemas.microsoft.com/office/2006/metadata/contentType"))

# Enumerate the schemas and print each element.
for schema in schemas:
    print(schema)

# Below are three ways of removing schemas from the collection.
# 1 -  Remove a schema by index:
schemas.remove_at(2)

# 2 -  Remove a schema by value:
schemas.remove("http://www.w3.org/2001/XMLSchema")

# 3 -  Use the "clear" method to empty the collection at once.
schemas.clear()

self.assertEqual(0, schemas.count)

See Also