XmlArrayItemAttribute::NestingLevel Property
Gets or sets the level in a hierarchy of XML elements that the XmlArrayItemAttribute affects.
Assembly: System.Xml (in System.Xml.dll)
An XML document can contain hierarchies of XML elements. To represent such a hierarchy, an array of arrays is used. In such an array, each index represents a level in the hierarchy. Therefore, the NestingLevel property is only used when applying an XmlArrayItemAttribute to a field that returns an array of arrays.
When applying the attribute, specify which hierarchy level the attribute affects by setting the NestingLevel. The first index always has the value of 0; therefore it is optional to set its NestingLevel --an XmlArrayItemAttribute without a NestingLevel value is applied to the first array index. Only the subsequent XmlArrayItemAttribute objects require NestingLevel values specified (as 1, 2, 3, and so forth).
The following example applies three XmlArrayItemAttribute attributes to an array of arrays. To specify which of the arrays each attribute applies to, the NestingLevel property is set to the index of the arrays.
#using <System.dll> #using <System.Xml.dll> using namespace System; using namespace System::Xml; using namespace System::Xml::Serialization; using namespace System::IO; public ref class Forest { // Set the NestingLevel for each array. The first // attribute (NestingLevel = 0) is optional. public: [XmlArrayItem(ElementName = "tree", NestingLevel = 0)] [XmlArrayItem(ElementName = "branch", NestingLevel = 1)] [XmlArrayItem(ElementName = "leaf",NestingLevel = 2)] array<array<array<String^>^>^>^ TreeArray; }; int main() { XmlSerializer^ serializer = gcnew XmlSerializer(Forest::typeid); Forest^ constructedForest = gcnew Forest(); array<array<array<String^>^>^>^ tree = gcnew array<array<array<String^>^>^>(2); array<array<String^>^>^ firstBranch = gcnew array<array<String^>^>(1); firstBranch[0] = gcnew array<String^>{"One"}; tree[0] = firstBranch; array<array<String^>^>^ secondBranch = gcnew array<array<String^>^>(2); secondBranch[0] = gcnew array<String^>{"One","Two"}; secondBranch[1] = gcnew array<String^>{"One","Two","Three"}; tree[1] = secondBranch; constructedForest->TreeArray = tree; serializer->Serialize(Console::Out, constructedForest); }
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