Item
Contents
[
Hide
]CustomXmlPropertyCollection indexer (1 of 2)
Gets a property with the specified name.
public CustomXmlProperty this[string name] { get; }
Parameter | Description |
---|---|
name | Case-sensitive name of the property to locate. |
Examples
Shows how to work with smart tag properties to get in depth information about smart tags.
Document doc = new Document(MyDir + "Smart tags.doc");
// A smart tag appears in a document with Microsoft Word recognizes a part of its text as some form of data,
// such as a name, date, or address, and converts it to a hyperlink that displays a purple dotted underline.
// In Word 2003, we can enable smart tags via "Tools" -> "AutoCorrect options..." -> "SmartTags".
// In our input document, there are three objects that Microsoft Word registered as smart tags.
// Smart tags may be nested, so this collection contains more.
SmartTag[] smartTags = doc.GetChildNodes(NodeType.SmartTag, true).OfType<SmartTag>().ToArray();
Assert.That(smartTags.Length, Is.EqualTo(8));
// The "Properties" member of a smart tag contains its metadata, which will be different for each type of smart tag.
// The properties of a "date"-type smart tag contain its year, month, and day.
CustomXmlPropertyCollection properties = smartTags[7].Properties;
Assert.That(properties.Count, Is.EqualTo(4));
using (IEnumerator<CustomXmlProperty> enumerator = properties.GetEnumerator())
{
while (enumerator.MoveNext())
{
Console.WriteLine($"Property name: {enumerator.Current.Name}, value: {enumerator.Current.Value}");
Assert.That(enumerator.Current.Uri, Is.EqualTo(""));
}
}
// We can also access the properties in various ways, such as a key-value pair.
Assert.That(properties.Contains("Day"), Is.True);
Assert.That(properties["Day"].Value, Is.EqualTo("22"));
Assert.That(properties[2].Value, Is.EqualTo("2003"));
Assert.That(properties.IndexOfKey("Month"), Is.EqualTo(1));
// Below are three ways of removing elements from the properties collection.
// 1 - Remove by index:
properties.RemoveAt(3);
Assert.That(properties.Count, Is.EqualTo(3));
// 2 - Remove by name:
properties.Remove("Year");
Assert.That(properties.Count, Is.EqualTo(2));
// 3 - Clear the entire collection at once:
properties.Clear();
Assert.That(properties.Count, Is.EqualTo(0));
See Also
- class CustomXmlProperty
- class CustomXmlPropertyCollection
- namespace Aspose.Words.Markup
- assembly Aspose.Words
CustomXmlPropertyCollection indexer (2 of 2)
Gets a property at the specified index.
public CustomXmlProperty this[int index] { get; }
Parameter | Description |
---|---|
index | Zero-based index of the property. |
Examples
Shows how to work with smart tag properties to get in depth information about smart tags.
Document doc = new Document(MyDir + "Smart tags.doc");
// A smart tag appears in a document with Microsoft Word recognizes a part of its text as some form of data,
// such as a name, date, or address, and converts it to a hyperlink that displays a purple dotted underline.
// In Word 2003, we can enable smart tags via "Tools" -> "AutoCorrect options..." -> "SmartTags".
// In our input document, there are three objects that Microsoft Word registered as smart tags.
// Smart tags may be nested, so this collection contains more.
SmartTag[] smartTags = doc.GetChildNodes(NodeType.SmartTag, true).OfType<SmartTag>().ToArray();
Assert.That(smartTags.Length, Is.EqualTo(8));
// The "Properties" member of a smart tag contains its metadata, which will be different for each type of smart tag.
// The properties of a "date"-type smart tag contain its year, month, and day.
CustomXmlPropertyCollection properties = smartTags[7].Properties;
Assert.That(properties.Count, Is.EqualTo(4));
using (IEnumerator<CustomXmlProperty> enumerator = properties.GetEnumerator())
{
while (enumerator.MoveNext())
{
Console.WriteLine($"Property name: {enumerator.Current.Name}, value: {enumerator.Current.Value}");
Assert.That(enumerator.Current.Uri, Is.EqualTo(""));
}
}
// We can also access the properties in various ways, such as a key-value pair.
Assert.That(properties.Contains("Day"), Is.True);
Assert.That(properties["Day"].Value, Is.EqualTo("22"));
Assert.That(properties[2].Value, Is.EqualTo("2003"));
Assert.That(properties.IndexOfKey("Month"), Is.EqualTo(1));
// Below are three ways of removing elements from the properties collection.
// 1 - Remove by index:
properties.RemoveAt(3);
Assert.That(properties.Count, Is.EqualTo(3));
// 2 - Remove by name:
properties.Remove("Year");
Assert.That(properties.Count, Is.EqualTo(2));
// 3 - Clear the entire collection at once:
properties.Clear();
Assert.That(properties.Count, Is.EqualTo(0));
See Also
- class CustomXmlProperty
- class CustomXmlPropertyCollection
- namespace Aspose.Words.Markup
- assembly Aspose.Words