Aspose::Words::Markup::CustomXmlProperty Class Reference

Detailed Description

Represents a single custom XML attribute or a smart tag property.

Used as an item of a CustomXmlPropertyCollection collection.

Examples

Shows how to create smart tags.

void Create()
{
auto doc = MakeObject<Document>();
// 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.
auto smartTag = MakeObject<SmartTag>(doc);
// Smart tags are composite nodes that contain their recognized text in its entirety.
// Add contents to this smart tag manually.
smartTag->AppendChild(MakeObject<Run>(doc, u"May 29, 2019"));
// Microsoft Word may recognize the above contents as being a date.
// Smart tags use the "Element" property to reflect the type of data they contain.
smartTag->set_Element(u"date");
// Some smart tag types process their contents further into custom XML properties.
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Day", String::Empty, u"29"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Month", String::Empty, u"5"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Year", String::Empty, u"2019"));
// Set the smart tag's URI to the default value.
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a date. "));
// Create another smart tag for a stock ticker.
smartTag = MakeObject<SmartTag>(doc);
smartTag->set_Element(u"stockticker");
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
smartTag->AppendChild(MakeObject<Run>(doc, u"MSFT"));
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a stock ticker."));
// Print all the smart tags in our document using a document visitor.
doc->Accept(MakeObject<ExSmartTag::SmartTagPrinter>());
// Older versions of Microsoft Word support smart tags.
doc->Save(ArtifactsDir + u"SmartTag.Create.doc");
// Use the "RemoveSmartTags" method to remove all smart tags from a document.
ASSERT_EQ(2, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
doc->RemoveSmartTags();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
}
class SmartTagPrinter : public DocumentVisitor
{
public:
VisitorAction VisitSmartTagStart(SharedPtr<SmartTag> smartTag) override
{
std::cout << "Smart tag type: " << smartTag->get_Element() << std::endl;
}
VisitorAction VisitSmartTagEnd(SharedPtr<SmartTag> smartTag) override
{
std::cout << "\tContents: \"" << smartTag->ToString(SaveFormat::Text) << "\"" << std::endl;
if (smartTag->get_Properties()->get_Count() == 0)
{
std::cout << "\tContains no properties" << std::endl;
}
else
{
std::cout << "\tProperties: ";
auto properties = MakeArray<String>(smartTag->get_Properties()->get_Count());
int index = 0;
for (const auto& cxp : System::IterateOver(smartTag->get_Properties()))
{
properties[index++] = String::Format(u"\"{0}\" = \"{1}\"", cxp->get_Name(), cxp->get_Value());
}
std::cout << String::Join(u", ", properties) << std::endl;
}
}
};

#include <Aspose.Words.Cpp/Markup/CustomXmlProperty.h>

+ Inheritance diagram for Aspose::Words::Markup::CustomXmlProperty:

Public Member Functions

 CustomXmlProperty (String name, String uri, String value)
 Initializes a new instance of this class. More...
 
String get_Name () const
 Specifies the name of the custom XML attribute or smart tag property. More...
 
String get_Uri () const
 Gets or sets the namespace URI of the custom XML attribute or smart tag property. More...
 
String get_Value () const
 Gets or sets the value of the custom XML attribute or smart tag property. More...
 
virtual const TypeInfoGetType () const override
 
virtual bool Is (const TypeInfo &target) const override
 
void set_Uri (String value)
 Setter for get_Uri. More...
 
void set_Value (String value)
 Setter for get_Value. More...
 

Static Public Member Functions

static const TypeInfoType ()
 

Constructor & Destructor Documentation

◆ CustomXmlProperty()

Aspose::Words::Markup::CustomXmlProperty::CustomXmlProperty ( System::String  name,
System::String  uri,
System::String  value 
)

Initializes a new instance of this class.

Parameters
nameThe name of the property. Cannot be null.
uriThe namespace URI of the property. Cannot be null.
valueThe value of the property. Cannot be null.
Examples

Shows how to create smart tags.

void Create()
{
auto doc = MakeObject<Document>();
// 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.
auto smartTag = MakeObject<SmartTag>(doc);
// Smart tags are composite nodes that contain their recognized text in its entirety.
// Add contents to this smart tag manually.
smartTag->AppendChild(MakeObject<Run>(doc, u"May 29, 2019"));
// Microsoft Word may recognize the above contents as being a date.
// Smart tags use the "Element" property to reflect the type of data they contain.
smartTag->set_Element(u"date");
// Some smart tag types process their contents further into custom XML properties.
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Day", String::Empty, u"29"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Month", String::Empty, u"5"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Year", String::Empty, u"2019"));
// Set the smart tag's URI to the default value.
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a date. "));
// Create another smart tag for a stock ticker.
smartTag = MakeObject<SmartTag>(doc);
smartTag->set_Element(u"stockticker");
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
smartTag->AppendChild(MakeObject<Run>(doc, u"MSFT"));
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a stock ticker."));
// Print all the smart tags in our document using a document visitor.
doc->Accept(MakeObject<ExSmartTag::SmartTagPrinter>());
// Older versions of Microsoft Word support smart tags.
doc->Save(ArtifactsDir + u"SmartTag.Create.doc");
// Use the "RemoveSmartTags" method to remove all smart tags from a document.
ASSERT_EQ(2, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
doc->RemoveSmartTags();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
}
class SmartTagPrinter : public DocumentVisitor
{
public:
VisitorAction VisitSmartTagStart(SharedPtr<SmartTag> smartTag) override
{
std::cout << "Smart tag type: " << smartTag->get_Element() << std::endl;
}
VisitorAction VisitSmartTagEnd(SharedPtr<SmartTag> smartTag) override
{
std::cout << "\tContents: \"" << smartTag->ToString(SaveFormat::Text) << "\"" << std::endl;
if (smartTag->get_Properties()->get_Count() == 0)
{
std::cout << "\tContains no properties" << std::endl;
}
else
{
std::cout << "\tProperties: ";
auto properties = MakeArray<String>(smartTag->get_Properties()->get_Count());
int index = 0;
for (const auto& cxp : System::IterateOver(smartTag->get_Properties()))
{
properties[index++] = String::Format(u"\"{0}\" = \"{1}\"", cxp->get_Name(), cxp->get_Value());
}
std::cout << String::Join(u", ", properties) << std::endl;
}
}
};

Member Function Documentation

◆ get_Name()

System::String Aspose::Words::Markup::CustomXmlProperty::get_Name ( ) const

Specifies the name of the custom XML attribute or smart tag property.

Cannot be null.

Default is empty string.

Examples

Shows how to create smart tags.

void Create()
{
auto doc = MakeObject<Document>();
// 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.
auto smartTag = MakeObject<SmartTag>(doc);
// Smart tags are composite nodes that contain their recognized text in its entirety.
// Add contents to this smart tag manually.
smartTag->AppendChild(MakeObject<Run>(doc, u"May 29, 2019"));
// Microsoft Word may recognize the above contents as being a date.
// Smart tags use the "Element" property to reflect the type of data they contain.
smartTag->set_Element(u"date");
// Some smart tag types process their contents further into custom XML properties.
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Day", String::Empty, u"29"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Month", String::Empty, u"5"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Year", String::Empty, u"2019"));
// Set the smart tag's URI to the default value.
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a date. "));
// Create another smart tag for a stock ticker.
smartTag = MakeObject<SmartTag>(doc);
smartTag->set_Element(u"stockticker");
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
smartTag->AppendChild(MakeObject<Run>(doc, u"MSFT"));
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a stock ticker."));
// Print all the smart tags in our document using a document visitor.
doc->Accept(MakeObject<ExSmartTag::SmartTagPrinter>());
// Older versions of Microsoft Word support smart tags.
doc->Save(ArtifactsDir + u"SmartTag.Create.doc");
// Use the "RemoveSmartTags" method to remove all smart tags from a document.
ASSERT_EQ(2, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
doc->RemoveSmartTags();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
}
class SmartTagPrinter : public DocumentVisitor
{
public:
VisitorAction VisitSmartTagStart(SharedPtr<SmartTag> smartTag) override
{
std::cout << "Smart tag type: " << smartTag->get_Element() << std::endl;
}
VisitorAction VisitSmartTagEnd(SharedPtr<SmartTag> smartTag) override
{
std::cout << "\tContents: \"" << smartTag->ToString(SaveFormat::Text) << "\"" << std::endl;
if (smartTag->get_Properties()->get_Count() == 0)
{
std::cout << "\tContains no properties" << std::endl;
}
else
{
std::cout << "\tProperties: ";
auto properties = MakeArray<String>(smartTag->get_Properties()->get_Count());
int index = 0;
for (const auto& cxp : System::IterateOver(smartTag->get_Properties()))
{
properties[index++] = String::Format(u"\"{0}\" = \"{1}\"", cxp->get_Name(), cxp->get_Value());
}
std::cout << String::Join(u", ", properties) << std::endl;
}
}
};

◆ get_Uri()

System::String Aspose::Words::Markup::CustomXmlProperty::get_Uri ( ) const

Gets or sets the namespace URI of the custom XML attribute or smart tag property.

Cannot be null.

Default is empty string.

Examples

Shows how to work with smart tag properties to get in depth information about smart tags.

auto doc = MakeObject<Document>(MyDir + u"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.
ArrayPtr<SharedPtr<SmartTag>> smartTags = doc->GetChildNodes(NodeType::SmartTag, true)->LINQ_OfType<SharedPtr<SmartTag>>()->LINQ_ToArray();
ASSERT_EQ(8, smartTags->get_Length());
// 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.
SharedPtr<CustomXmlPropertyCollection> properties = smartTags[7]->get_Properties();
ASSERT_EQ(4, properties->get_Count());
{
SharedPtr<System::Collections::Generic::IEnumerator<SharedPtr<CustomXmlProperty>>> enumerator = properties->GetEnumerator();
while (enumerator->MoveNext())
{
std::cout << "Property name: " << enumerator->get_Current()->get_Name() << ", value: " << enumerator->get_Current()->get_Value() << std::endl;
ASSERT_EQ(u"", enumerator->get_Current()->get_Uri());
}
}
// We can also access the properties in various ways, such as a key-value pair.
ASSERT_TRUE(properties->Contains(u"Day"));
ASSERT_EQ(u"22", properties->idx_get(u"Day")->get_Value());
ASSERT_EQ(u"2003", properties->idx_get(2)->get_Value());
ASSERT_EQ(1, properties->IndexOfKey(u"Month"));
// Below are three ways of removing elements from the properties collection.
// 1 - Remove by index:
properties->RemoveAt(3);
ASSERT_EQ(3, properties->get_Count());
// 2 - Remove by name:
properties->Remove(u"Year");
ASSERT_EQ(2, properties->get_Count());
// 3 - Clear the entire collection at once:
properties->Clear();
ASSERT_EQ(0, properties->get_Count());

◆ get_Value()

System::String Aspose::Words::Markup::CustomXmlProperty::get_Value ( ) const

Gets or sets the value of the custom XML attribute or smart tag property.

Cannot be null.

Default is empty string.

Examples

Shows how to create smart tags.

void Create()
{
auto doc = MakeObject<Document>();
// 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.
auto smartTag = MakeObject<SmartTag>(doc);
// Smart tags are composite nodes that contain their recognized text in its entirety.
// Add contents to this smart tag manually.
smartTag->AppendChild(MakeObject<Run>(doc, u"May 29, 2019"));
// Microsoft Word may recognize the above contents as being a date.
// Smart tags use the "Element" property to reflect the type of data they contain.
smartTag->set_Element(u"date");
// Some smart tag types process their contents further into custom XML properties.
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Day", String::Empty, u"29"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Month", String::Empty, u"5"));
smartTag->get_Properties()->Add(MakeObject<CustomXmlProperty>(u"Year", String::Empty, u"2019"));
// Set the smart tag's URI to the default value.
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a date. "));
// Create another smart tag for a stock ticker.
smartTag = MakeObject<SmartTag>(doc);
smartTag->set_Element(u"stockticker");
smartTag->set_Uri(u"urn:schemas-microsoft-com:office:smarttags");
smartTag->AppendChild(MakeObject<Run>(doc, u"MSFT"));
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(smartTag);
doc->get_FirstSection()->get_Body()->get_FirstParagraph()->AppendChild(MakeObject<Run>(doc, u" is a stock ticker."));
// Print all the smart tags in our document using a document visitor.
doc->Accept(MakeObject<ExSmartTag::SmartTagPrinter>());
// Older versions of Microsoft Word support smart tags.
doc->Save(ArtifactsDir + u"SmartTag.Create.doc");
// Use the "RemoveSmartTags" method to remove all smart tags from a document.
ASSERT_EQ(2, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
doc->RemoveSmartTags();
ASSERT_EQ(0, doc->GetChildNodes(NodeType::SmartTag, true)->get_Count());
}
class SmartTagPrinter : public DocumentVisitor
{
public:
VisitorAction VisitSmartTagStart(SharedPtr<SmartTag> smartTag) override
{
std::cout << "Smart tag type: " << smartTag->get_Element() << std::endl;
}
VisitorAction VisitSmartTagEnd(SharedPtr<SmartTag> smartTag) override
{
std::cout << "\tContents: \"" << smartTag->ToString(SaveFormat::Text) << "\"" << std::endl;
if (smartTag->get_Properties()->get_Count() == 0)
{
std::cout << "\tContains no properties" << std::endl;
}
else
{
std::cout << "\tProperties: ";
auto properties = MakeArray<String>(smartTag->get_Properties()->get_Count());
int index = 0;
for (const auto& cxp : System::IterateOver(smartTag->get_Properties()))
{
properties[index++] = String::Format(u"\"{0}\" = \"{1}\"", cxp->get_Name(), cxp->get_Value());
}
std::cout << String::Join(u", ", properties) << std::endl;
}
}
};

◆ GetType()

virtual const System::TypeInfo& Aspose::Words::Markup::CustomXmlProperty::GetType ( ) const
overridevirtual

Reimplemented from System::Object.

◆ Is()

virtual bool Aspose::Words::Markup::CustomXmlProperty::Is ( const System::TypeInfo target) const
overridevirtual

Reimplemented from System::Object.

◆ set_Uri()

void Aspose::Words::Markup::CustomXmlProperty::set_Uri ( System::String  value)

◆ set_Value()

void Aspose::Words::Markup::CustomXmlProperty::set_Value ( System::String  value)

◆ Type()

static const System::TypeInfo& Aspose::Words::Markup::CustomXmlProperty::Type ( )
static