XmlArrayAttribute Constructor (String^)
.NET Framework (current version)
Initializes a new instance of the XmlArrayAttribute class and specifies the XML element name generated in the XML document instance.
Assembly: System.Xml (in System.Xml.dll)
Parameters
- elementName
-
Type:
System::String^
The name of the XML element that the XmlSerializer generates.
For more information about using attributes, see Extending Metadata Using Attributes.
The following example assigns the XmlArrayAttribute to two arrays, and serializes a class instance that contains those arrays.
#using <System.Xml.dll> #using <System.dll> using namespace System; using namespace System::IO; using namespace System::Xml; using namespace System::Xml::Serialization; public ref class MyClass { public: [XmlArrayAttribute("MyStrings")] array<String^>^MyStringArray; [XmlArrayAttribute(ElementName="MyIntegers")] array<Int32>^MyIntegerArray; }; int main() { String^ filename = "MyClass.xml"; // Creates a new instance of the XmlSerializer class. XmlSerializer^ s = gcnew XmlSerializer( MyClass::typeid ); // Needs a StreamWriter to write the file. TextWriter^ myWriter = gcnew StreamWriter( filename ); MyClass^ myClass = gcnew MyClass; // Creates and populates a string array, then assigns // it to the MyStringArray property. array<String^>^myStrings = {"Hello","World","!"}; myClass->MyStringArray = myStrings; /* Creates and populates an integer array, and assigns it to the MyIntegerArray property. */ array<Int32>^myIntegers = {1,2,3}; myClass->MyIntegerArray = myIntegers; // Serializes the class, and writes it to disk. s->Serialize( myWriter, myClass ); myWriter->Close(); }
<?xml version="1.0"?> <MyClass1 xmlns:xsi="http://www.w3.org/1999/XMLSchema-instance" xmlns:xsd="http://www.w3.org/1999/XMLSchema"> <MyStrings> <string>Hello</string> <string>World</string> <string>!</string> </MyStrings> <MyIntegers> <int>1</int> <int>2</int> <int>3</int> </MyIntegers> </MyClass1>
Universal Windows Platform
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Available since 8
.NET Framework
Available since 1.1
Portable Class Library
Supported in: portable .NET platforms
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.0
Windows Phone
Available since 8.1
Show: