com.aspose.words

Class CustomXmlPropertyCollection

  • java.lang.Object
    • com.aspose.words.CustomXmlPropertyCollection
  • All Implemented Interfaces:
    java.lang.Iterable
    public class CustomXmlPropertyCollection 
    extends java.lang.Object

Represents a collection of custom XML attributes or smart tag properties.

Items are CustomXmlProperty objects.

Example:

Shows how to work with smart tag properties to get in depth information about smart tags.
// Open a document that contains smart tags and their collection
Document doc = new Document(getMyDir() + "SmartTags.doc");

// Smart tags are an older Microsoft Word feature that can automatically detect and tag
// any parts of the text that it registers as commonly used information objects such as names, addresses, stock tickers, dates etc
// In Word 2003, smart tags can be turned on in Tools > AutoCorrect options... > SmartTags tab
// In our input document there are three objects that were registered as smart tags, but since they can be nested, we have 8 in this collection
NodeCollection smartTags = doc.getChildNodes(NodeType.SMART_TAG, true);
Assert.assertEquals(smartTags.getCount(), 8);

// The last smart tag is of the "Date" type, which we will retrieve here
SmartTag smartTag = (SmartTag) smartTags.get(7);

// The Properties attribute, for some smart tags, elaborates on the text object that Word picked up as a smart tag
// In the case of our "Date" smart tag, its properties will let us know the year, month and day within the smart tag
CustomXmlPropertyCollection properties = smartTag.getProperties();

// We can enumerate over the collection and print the aforementioned properties to the console
Assert.assertEquals(properties.getCount(), 4);

Iterator<CustomXmlProperty> enumerator = properties.iterator();
try {
    while (enumerator.hasNext()) {
        CustomXmlProperty customXmlProperty = enumerator.next();

        System.out.println(MessageFormat.format("Property name: {0}, value: {1}", customXmlProperty.getName(), customXmlProperty.getValue()));
        Assert.assertEquals(enumerator.next().getUri(), "");
    }
} finally {
    if (enumerator != null) enumerator.remove();
}

// We can also access the elements in various ways, including as a key-value pair
Assert.assertTrue(properties.contains("Day"));
Assert.assertEquals(properties.get("Day").getValue(), "22");
Assert.assertEquals(properties.get(2).getValue(), "2003");
Assert.assertEquals(properties.indexOfKey("Month"), 1);

// We can also remove elements by name, index or clear the collection entirely
properties.removeAt(3);
properties.remove("Year");
Assert.assertEquals((properties.getCount()), 2);

properties.clear();
Assert.assertEquals((properties.getCount()), 0);

// We can remove the entire smart tag like this
smartTag.remove();

Property Getters/Setters Summary
intgetCount()
Gets the number of elements contained in the collection.
CustomXmlPropertyget(int index)
Gets a property at the specified index.
CustomXmlPropertyget(java.lang.String name)
Gets a property with the specified name.
 
Method Summary
voidadd(CustomXmlProperty property)
Adds a property to the collection.
voidclear()
Removes all elements from the collection.
booleancontains(java.lang.String name)
Determines whether the collection contains a property with the given name.
intindexOfKey(java.lang.String name)
Returns the zero-based index of the specified property in the collection.
java.util.Iterator<CustomXmlProperty>iterator()
Returns an iterator object that can be used to iterate over all items in the collection.
voidremove(java.lang.String name)
Removes a property with the specified name from the collection.
voidremoveAt(int index)
Removes a property at the specified index.
 

    • Property Getters/Setters Detail

      • getCount

        public int getCount()
        
        Gets the number of elements contained in the collection.

        Example:

        Shows how to work with smart tag properties to get in depth information about smart tags.
        // Open a document that contains smart tags and their collection
        Document doc = new Document(getMyDir() + "SmartTags.doc");
        
        // Smart tags are an older Microsoft Word feature that can automatically detect and tag
        // any parts of the text that it registers as commonly used information objects such as names, addresses, stock tickers, dates etc
        // In Word 2003, smart tags can be turned on in Tools > AutoCorrect options... > SmartTags tab
        // In our input document there are three objects that were registered as smart tags, but since they can be nested, we have 8 in this collection
        NodeCollection smartTags = doc.getChildNodes(NodeType.SMART_TAG, true);
        Assert.assertEquals(smartTags.getCount(), 8);
        
        // The last smart tag is of the "Date" type, which we will retrieve here
        SmartTag smartTag = (SmartTag) smartTags.get(7);
        
        // The Properties attribute, for some smart tags, elaborates on the text object that Word picked up as a smart tag
        // In the case of our "Date" smart tag, its properties will let us know the year, month and day within the smart tag
        CustomXmlPropertyCollection properties = smartTag.getProperties();
        
        // We can enumerate over the collection and print the aforementioned properties to the console
        Assert.assertEquals(properties.getCount(), 4);
        
        Iterator<CustomXmlProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                CustomXmlProperty customXmlProperty = enumerator.next();
        
                System.out.println(MessageFormat.format("Property name: {0}, value: {1}", customXmlProperty.getName(), customXmlProperty.getValue()));
                Assert.assertEquals(enumerator.next().getUri(), "");
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can also access the elements in various ways, including as a key-value pair
        Assert.assertTrue(properties.contains("Day"));
        Assert.assertEquals(properties.get("Day").getValue(), "22");
        Assert.assertEquals(properties.get(2).getValue(), "2003");
        Assert.assertEquals(properties.indexOfKey("Month"), 1);
        
        // We can also remove elements by name, index or clear the collection entirely
        properties.removeAt(3);
        properties.remove("Year");
        Assert.assertEquals((properties.getCount()), 2);
        
        properties.clear();
        Assert.assertEquals((properties.getCount()), 0);
        
        // We can remove the entire smart tag like this
        smartTag.remove();
      • get

        public CustomXmlProperty get(int index)
        
        Gets a property at the specified index.
        Parameters:
        index - Zero-based index of the property.

        Example:

        Shows how to work with smart tag properties to get in depth information about smart tags.
        // Open a document that contains smart tags and their collection
        Document doc = new Document(getMyDir() + "SmartTags.doc");
        
        // Smart tags are an older Microsoft Word feature that can automatically detect and tag
        // any parts of the text that it registers as commonly used information objects such as names, addresses, stock tickers, dates etc
        // In Word 2003, smart tags can be turned on in Tools > AutoCorrect options... > SmartTags tab
        // In our input document there are three objects that were registered as smart tags, but since they can be nested, we have 8 in this collection
        NodeCollection smartTags = doc.getChildNodes(NodeType.SMART_TAG, true);
        Assert.assertEquals(smartTags.getCount(), 8);
        
        // The last smart tag is of the "Date" type, which we will retrieve here
        SmartTag smartTag = (SmartTag) smartTags.get(7);
        
        // The Properties attribute, for some smart tags, elaborates on the text object that Word picked up as a smart tag
        // In the case of our "Date" smart tag, its properties will let us know the year, month and day within the smart tag
        CustomXmlPropertyCollection properties = smartTag.getProperties();
        
        // We can enumerate over the collection and print the aforementioned properties to the console
        Assert.assertEquals(properties.getCount(), 4);
        
        Iterator<CustomXmlProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                CustomXmlProperty customXmlProperty = enumerator.next();
        
                System.out.println(MessageFormat.format("Property name: {0}, value: {1}", customXmlProperty.getName(), customXmlProperty.getValue()));
                Assert.assertEquals(enumerator.next().getUri(), "");
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can also access the elements in various ways, including as a key-value pair
        Assert.assertTrue(properties.contains("Day"));
        Assert.assertEquals(properties.get("Day").getValue(), "22");
        Assert.assertEquals(properties.get(2).getValue(), "2003");
        Assert.assertEquals(properties.indexOfKey("Month"), 1);
        
        // We can also remove elements by name, index or clear the collection entirely
        properties.removeAt(3);
        properties.remove("Year");
        Assert.assertEquals((properties.getCount()), 2);
        
        properties.clear();
        Assert.assertEquals((properties.getCount()), 0);
        
        // We can remove the entire smart tag like this
        smartTag.remove();
      • get

        public CustomXmlProperty get(java.lang.String name)
        
        Gets a property with the specified name.
        Parameters:
        name - Case-sensitive name of the property to locate.

        Example:

        Shows how to work with smart tag properties to get in depth information about smart tags.
        // Open a document that contains smart tags and their collection
        Document doc = new Document(getMyDir() + "SmartTags.doc");
        
        // Smart tags are an older Microsoft Word feature that can automatically detect and tag
        // any parts of the text that it registers as commonly used information objects such as names, addresses, stock tickers, dates etc
        // In Word 2003, smart tags can be turned on in Tools > AutoCorrect options... > SmartTags tab
        // In our input document there are three objects that were registered as smart tags, but since they can be nested, we have 8 in this collection
        NodeCollection smartTags = doc.getChildNodes(NodeType.SMART_TAG, true);
        Assert.assertEquals(smartTags.getCount(), 8);
        
        // The last smart tag is of the "Date" type, which we will retrieve here
        SmartTag smartTag = (SmartTag) smartTags.get(7);
        
        // The Properties attribute, for some smart tags, elaborates on the text object that Word picked up as a smart tag
        // In the case of our "Date" smart tag, its properties will let us know the year, month and day within the smart tag
        CustomXmlPropertyCollection properties = smartTag.getProperties();
        
        // We can enumerate over the collection and print the aforementioned properties to the console
        Assert.assertEquals(properties.getCount(), 4);
        
        Iterator<CustomXmlProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                CustomXmlProperty customXmlProperty = enumerator.next();
        
                System.out.println(MessageFormat.format("Property name: {0}, value: {1}", customXmlProperty.getName(), customXmlProperty.getValue()));
                Assert.assertEquals(enumerator.next().getUri(), "");
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can also access the elements in various ways, including as a key-value pair
        Assert.assertTrue(properties.contains("Day"));
        Assert.assertEquals(properties.get("Day").getValue(), "22");
        Assert.assertEquals(properties.get(2).getValue(), "2003");
        Assert.assertEquals(properties.indexOfKey("Month"), 1);
        
        // We can also remove elements by name, index or clear the collection entirely
        properties.removeAt(3);
        properties.remove("Year");
        Assert.assertEquals((properties.getCount()), 2);
        
        properties.clear();
        Assert.assertEquals((properties.getCount()), 0);
        
        // We can remove the entire smart tag like this
        smartTag.remove();
    • Method Detail

      • add

        public void add(CustomXmlProperty property)
        Adds a property to the collection.
        Parameters:
        property - The property to add.

        Example:

        Shows how to work with smart tag properties to get in depth information about smart tags.
        // Open a document that contains smart tags and their collection
        Document doc = new Document(getMyDir() + "SmartTags.doc");
        
        // Smart tags are an older Microsoft Word feature that can automatically detect and tag
        // any parts of the text that it registers as commonly used information objects such as names, addresses, stock tickers, dates etc
        // In Word 2003, smart tags can be turned on in Tools > AutoCorrect options... > SmartTags tab
        // In our input document there are three objects that were registered as smart tags, but since they can be nested, we have 8 in this collection
        NodeCollection smartTags = doc.getChildNodes(NodeType.SMART_TAG, true);
        Assert.assertEquals(smartTags.getCount(), 8);
        
        // The last smart tag is of the "Date" type, which we will retrieve here
        SmartTag smartTag = (SmartTag) smartTags.get(7);
        
        // The Properties attribute, for some smart tags, elaborates on the text object that Word picked up as a smart tag
        // In the case of our "Date" smart tag, its properties will let us know the year, month and day within the smart tag
        CustomXmlPropertyCollection properties = smartTag.getProperties();
        
        // We can enumerate over the collection and print the aforementioned properties to the console
        Assert.assertEquals(properties.getCount(), 4);
        
        Iterator<CustomXmlProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                CustomXmlProperty customXmlProperty = enumerator.next();
        
                System.out.println(MessageFormat.format("Property name: {0}, value: {1}", customXmlProperty.getName(), customXmlProperty.getValue()));
                Assert.assertEquals(enumerator.next().getUri(), "");
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can also access the elements in various ways, including as a key-value pair
        Assert.assertTrue(properties.contains("Day"));
        Assert.assertEquals(properties.get("Day").getValue(), "22");
        Assert.assertEquals(properties.get(2).getValue(), "2003");
        Assert.assertEquals(properties.indexOfKey("Month"), 1);
        
        // We can also remove elements by name, index or clear the collection entirely
        properties.removeAt(3);
        properties.remove("Year");
        Assert.assertEquals((properties.getCount()), 2);
        
        properties.clear();
        Assert.assertEquals((properties.getCount()), 0);
        
        // We can remove the entire smart tag like this
        smartTag.remove();
      • clear

        public void clear()
        Removes all elements from the collection.

        Example:

        Shows how to work with smart tag properties to get in depth information about smart tags.
        // Open a document that contains smart tags and their collection
        Document doc = new Document(getMyDir() + "SmartTags.doc");
        
        // Smart tags are an older Microsoft Word feature that can automatically detect and tag
        // any parts of the text that it registers as commonly used information objects such as names, addresses, stock tickers, dates etc
        // In Word 2003, smart tags can be turned on in Tools > AutoCorrect options... > SmartTags tab
        // In our input document there are three objects that were registered as smart tags, but since they can be nested, we have 8 in this collection
        NodeCollection smartTags = doc.getChildNodes(NodeType.SMART_TAG, true);
        Assert.assertEquals(smartTags.getCount(), 8);
        
        // The last smart tag is of the "Date" type, which we will retrieve here
        SmartTag smartTag = (SmartTag) smartTags.get(7);
        
        // The Properties attribute, for some smart tags, elaborates on the text object that Word picked up as a smart tag
        // In the case of our "Date" smart tag, its properties will let us know the year, month and day within the smart tag
        CustomXmlPropertyCollection properties = smartTag.getProperties();
        
        // We can enumerate over the collection and print the aforementioned properties to the console
        Assert.assertEquals(properties.getCount(), 4);
        
        Iterator<CustomXmlProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                CustomXmlProperty customXmlProperty = enumerator.next();
        
                System.out.println(MessageFormat.format("Property name: {0}, value: {1}", customXmlProperty.getName(), customXmlProperty.getValue()));
                Assert.assertEquals(enumerator.next().getUri(), "");
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can also access the elements in various ways, including as a key-value pair
        Assert.assertTrue(properties.contains("Day"));
        Assert.assertEquals(properties.get("Day").getValue(), "22");
        Assert.assertEquals(properties.get(2).getValue(), "2003");
        Assert.assertEquals(properties.indexOfKey("Month"), 1);
        
        // We can also remove elements by name, index or clear the collection entirely
        properties.removeAt(3);
        properties.remove("Year");
        Assert.assertEquals((properties.getCount()), 2);
        
        properties.clear();
        Assert.assertEquals((properties.getCount()), 0);
        
        // We can remove the entire smart tag like this
        smartTag.remove();
      • contains

        public boolean contains(java.lang.String name)
        Determines whether the collection contains a property with the given name.
        Parameters:
        name - Case-sensitive name of the property to locate.
        Returns:
        True if the item is found in the collection; otherwise, false.

        Example:

        Shows how to work with smart tag properties to get in depth information about smart tags.
        // Open a document that contains smart tags and their collection
        Document doc = new Document(getMyDir() + "SmartTags.doc");
        
        // Smart tags are an older Microsoft Word feature that can automatically detect and tag
        // any parts of the text that it registers as commonly used information objects such as names, addresses, stock tickers, dates etc
        // In Word 2003, smart tags can be turned on in Tools > AutoCorrect options... > SmartTags tab
        // In our input document there are three objects that were registered as smart tags, but since they can be nested, we have 8 in this collection
        NodeCollection smartTags = doc.getChildNodes(NodeType.SMART_TAG, true);
        Assert.assertEquals(smartTags.getCount(), 8);
        
        // The last smart tag is of the "Date" type, which we will retrieve here
        SmartTag smartTag = (SmartTag) smartTags.get(7);
        
        // The Properties attribute, for some smart tags, elaborates on the text object that Word picked up as a smart tag
        // In the case of our "Date" smart tag, its properties will let us know the year, month and day within the smart tag
        CustomXmlPropertyCollection properties = smartTag.getProperties();
        
        // We can enumerate over the collection and print the aforementioned properties to the console
        Assert.assertEquals(properties.getCount(), 4);
        
        Iterator<CustomXmlProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                CustomXmlProperty customXmlProperty = enumerator.next();
        
                System.out.println(MessageFormat.format("Property name: {0}, value: {1}", customXmlProperty.getName(), customXmlProperty.getValue()));
                Assert.assertEquals(enumerator.next().getUri(), "");
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can also access the elements in various ways, including as a key-value pair
        Assert.assertTrue(properties.contains("Day"));
        Assert.assertEquals(properties.get("Day").getValue(), "22");
        Assert.assertEquals(properties.get(2).getValue(), "2003");
        Assert.assertEquals(properties.indexOfKey("Month"), 1);
        
        // We can also remove elements by name, index or clear the collection entirely
        properties.removeAt(3);
        properties.remove("Year");
        Assert.assertEquals((properties.getCount()), 2);
        
        properties.clear();
        Assert.assertEquals((properties.getCount()), 0);
        
        // We can remove the entire smart tag like this
        smartTag.remove();
      • indexOfKey

        public int indexOfKey(java.lang.String name)
        Returns the zero-based index of the specified property in the collection.
        Parameters:
        name - The case-sensitive name of the property.
        Returns:
        The zero based index. Negative value if not found.

        Example:

        Shows how to work with smart tag properties to get in depth information about smart tags.
        // Open a document that contains smart tags and their collection
        Document doc = new Document(getMyDir() + "SmartTags.doc");
        
        // Smart tags are an older Microsoft Word feature that can automatically detect and tag
        // any parts of the text that it registers as commonly used information objects such as names, addresses, stock tickers, dates etc
        // In Word 2003, smart tags can be turned on in Tools > AutoCorrect options... > SmartTags tab
        // In our input document there are three objects that were registered as smart tags, but since they can be nested, we have 8 in this collection
        NodeCollection smartTags = doc.getChildNodes(NodeType.SMART_TAG, true);
        Assert.assertEquals(smartTags.getCount(), 8);
        
        // The last smart tag is of the "Date" type, which we will retrieve here
        SmartTag smartTag = (SmartTag) smartTags.get(7);
        
        // The Properties attribute, for some smart tags, elaborates on the text object that Word picked up as a smart tag
        // In the case of our "Date" smart tag, its properties will let us know the year, month and day within the smart tag
        CustomXmlPropertyCollection properties = smartTag.getProperties();
        
        // We can enumerate over the collection and print the aforementioned properties to the console
        Assert.assertEquals(properties.getCount(), 4);
        
        Iterator<CustomXmlProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                CustomXmlProperty customXmlProperty = enumerator.next();
        
                System.out.println(MessageFormat.format("Property name: {0}, value: {1}", customXmlProperty.getName(), customXmlProperty.getValue()));
                Assert.assertEquals(enumerator.next().getUri(), "");
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can also access the elements in various ways, including as a key-value pair
        Assert.assertTrue(properties.contains("Day"));
        Assert.assertEquals(properties.get("Day").getValue(), "22");
        Assert.assertEquals(properties.get(2).getValue(), "2003");
        Assert.assertEquals(properties.indexOfKey("Month"), 1);
        
        // We can also remove elements by name, index or clear the collection entirely
        properties.removeAt(3);
        properties.remove("Year");
        Assert.assertEquals((properties.getCount()), 2);
        
        properties.clear();
        Assert.assertEquals((properties.getCount()), 0);
        
        // We can remove the entire smart tag like this
        smartTag.remove();
      • iterator

        public java.util.Iterator<CustomXmlProperty> iterator()
        Returns an iterator object that can be used to iterate over all items in the collection.

        Example:

        Shows how to work with smart tag properties to get in depth information about smart tags.
        // Open a document that contains smart tags and their collection
        Document doc = new Document(getMyDir() + "SmartTags.doc");
        
        // Smart tags are an older Microsoft Word feature that can automatically detect and tag
        // any parts of the text that it registers as commonly used information objects such as names, addresses, stock tickers, dates etc
        // In Word 2003, smart tags can be turned on in Tools > AutoCorrect options... > SmartTags tab
        // In our input document there are three objects that were registered as smart tags, but since they can be nested, we have 8 in this collection
        NodeCollection smartTags = doc.getChildNodes(NodeType.SMART_TAG, true);
        Assert.assertEquals(smartTags.getCount(), 8);
        
        // The last smart tag is of the "Date" type, which we will retrieve here
        SmartTag smartTag = (SmartTag) smartTags.get(7);
        
        // The Properties attribute, for some smart tags, elaborates on the text object that Word picked up as a smart tag
        // In the case of our "Date" smart tag, its properties will let us know the year, month and day within the smart tag
        CustomXmlPropertyCollection properties = smartTag.getProperties();
        
        // We can enumerate over the collection and print the aforementioned properties to the console
        Assert.assertEquals(properties.getCount(), 4);
        
        Iterator<CustomXmlProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                CustomXmlProperty customXmlProperty = enumerator.next();
        
                System.out.println(MessageFormat.format("Property name: {0}, value: {1}", customXmlProperty.getName(), customXmlProperty.getValue()));
                Assert.assertEquals(enumerator.next().getUri(), "");
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can also access the elements in various ways, including as a key-value pair
        Assert.assertTrue(properties.contains("Day"));
        Assert.assertEquals(properties.get("Day").getValue(), "22");
        Assert.assertEquals(properties.get(2).getValue(), "2003");
        Assert.assertEquals(properties.indexOfKey("Month"), 1);
        
        // We can also remove elements by name, index or clear the collection entirely
        properties.removeAt(3);
        properties.remove("Year");
        Assert.assertEquals((properties.getCount()), 2);
        
        properties.clear();
        Assert.assertEquals((properties.getCount()), 0);
        
        // We can remove the entire smart tag like this
        smartTag.remove();
      • remove

        public void remove(java.lang.String name)
        Removes a property with the specified name from the collection.
        Parameters:
        name - The case-sensitive name of the property.

        Example:

        Shows how to work with smart tag properties to get in depth information about smart tags.
        // Open a document that contains smart tags and their collection
        Document doc = new Document(getMyDir() + "SmartTags.doc");
        
        // Smart tags are an older Microsoft Word feature that can automatically detect and tag
        // any parts of the text that it registers as commonly used information objects such as names, addresses, stock tickers, dates etc
        // In Word 2003, smart tags can be turned on in Tools > AutoCorrect options... > SmartTags tab
        // In our input document there are three objects that were registered as smart tags, but since they can be nested, we have 8 in this collection
        NodeCollection smartTags = doc.getChildNodes(NodeType.SMART_TAG, true);
        Assert.assertEquals(smartTags.getCount(), 8);
        
        // The last smart tag is of the "Date" type, which we will retrieve here
        SmartTag smartTag = (SmartTag) smartTags.get(7);
        
        // The Properties attribute, for some smart tags, elaborates on the text object that Word picked up as a smart tag
        // In the case of our "Date" smart tag, its properties will let us know the year, month and day within the smart tag
        CustomXmlPropertyCollection properties = smartTag.getProperties();
        
        // We can enumerate over the collection and print the aforementioned properties to the console
        Assert.assertEquals(properties.getCount(), 4);
        
        Iterator<CustomXmlProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                CustomXmlProperty customXmlProperty = enumerator.next();
        
                System.out.println(MessageFormat.format("Property name: {0}, value: {1}", customXmlProperty.getName(), customXmlProperty.getValue()));
                Assert.assertEquals(enumerator.next().getUri(), "");
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can also access the elements in various ways, including as a key-value pair
        Assert.assertTrue(properties.contains("Day"));
        Assert.assertEquals(properties.get("Day").getValue(), "22");
        Assert.assertEquals(properties.get(2).getValue(), "2003");
        Assert.assertEquals(properties.indexOfKey("Month"), 1);
        
        // We can also remove elements by name, index or clear the collection entirely
        properties.removeAt(3);
        properties.remove("Year");
        Assert.assertEquals((properties.getCount()), 2);
        
        properties.clear();
        Assert.assertEquals((properties.getCount()), 0);
        
        // We can remove the entire smart tag like this
        smartTag.remove();
      • removeAt

        public void removeAt(int index)
        Removes a property at the specified index.
        Parameters:
        index - The zero based index.

        Example:

        Shows how to work with smart tag properties to get in depth information about smart tags.
        // Open a document that contains smart tags and their collection
        Document doc = new Document(getMyDir() + "SmartTags.doc");
        
        // Smart tags are an older Microsoft Word feature that can automatically detect and tag
        // any parts of the text that it registers as commonly used information objects such as names, addresses, stock tickers, dates etc
        // In Word 2003, smart tags can be turned on in Tools > AutoCorrect options... > SmartTags tab
        // In our input document there are three objects that were registered as smart tags, but since they can be nested, we have 8 in this collection
        NodeCollection smartTags = doc.getChildNodes(NodeType.SMART_TAG, true);
        Assert.assertEquals(smartTags.getCount(), 8);
        
        // The last smart tag is of the "Date" type, which we will retrieve here
        SmartTag smartTag = (SmartTag) smartTags.get(7);
        
        // The Properties attribute, for some smart tags, elaborates on the text object that Word picked up as a smart tag
        // In the case of our "Date" smart tag, its properties will let us know the year, month and day within the smart tag
        CustomXmlPropertyCollection properties = smartTag.getProperties();
        
        // We can enumerate over the collection and print the aforementioned properties to the console
        Assert.assertEquals(properties.getCount(), 4);
        
        Iterator<CustomXmlProperty> enumerator = properties.iterator();
        try {
            while (enumerator.hasNext()) {
                CustomXmlProperty customXmlProperty = enumerator.next();
        
                System.out.println(MessageFormat.format("Property name: {0}, value: {1}", customXmlProperty.getName(), customXmlProperty.getValue()));
                Assert.assertEquals(enumerator.next().getUri(), "");
            }
        } finally {
            if (enumerator != null) enumerator.remove();
        }
        
        // We can also access the elements in various ways, including as a key-value pair
        Assert.assertTrue(properties.contains("Day"));
        Assert.assertEquals(properties.get("Day").getValue(), "22");
        Assert.assertEquals(properties.get(2).getValue(), "2003");
        Assert.assertEquals(properties.indexOfKey("Month"), 1);
        
        // We can also remove elements by name, index or clear the collection entirely
        properties.removeAt(3);
        properties.remove("Year");
        Assert.assertEquals((properties.getCount()), 2);
        
        properties.clear();
        Assert.assertEquals((properties.getCount()), 0);
        
        // We can remove the entire smart tag like this
        smartTag.remove();