XmlArrayItemAttribute.NestingLevel 속성

정의

XML 요소 계층 구조에서 XmlArrayItemAttribute가 영향을 주는 수준을 가져오거나 설정합니다.

public:
 property int NestingLevel { int get(); void set(int value); };
public int NestingLevel { get; set; }
member this.NestingLevel : int with get, set
Public Property NestingLevel As Integer

속성 값

Int32

배열의 배열에 있는 인덱스 집합의 인덱스(0부터 시작)입니다.

예제

다음 예제에서는 배열 배열에 세 XmlArrayItemAttribute 가지 특성을 적용합니다. 각 특성이 적용되는 배열을 지정하기 위해 NestingLevel 속성은 배열의 인덱스로 설정됩니다.

#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);
}
using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;

public class Forest{
   /* Set the NestingLevel for each array. The first
   attribute (NestingLevel = 0) is optional. */
   [XmlArrayItem(ElementName = "tree", NestingLevel = 0)]
   [XmlArrayItem(ElementName = "branch", NestingLevel = 1)]
   [XmlArrayItem(ElementName = "leaf",NestingLevel = 2)]
   public string[][][] TreeArray;
}

public class Test{
   public static void Main(){
      Test t = new Test();
      t.SerializeObject("Tree.xml");
   }
   private void SerializeObject(string filename){
      XmlSerializer serializer =
      new XmlSerializer(typeof(Forest));

      Forest f = new Forest();
      string[][][] myTreeArray = new string[2] [][];

      string[][]myBranchArray1= new string[1][];
      myBranchArray1[0]=new string[1]{"One"};
      myTreeArray[0]=myBranchArray1;

      string[][]myBranchArray2= new string[2][];
      myBranchArray2[0]=new string[2]{"One","Two"};
      myBranchArray2[1]=new string[3]{"One","Two","Three"};
      myTreeArray[1]=myBranchArray2;

      f.TreeArray=myTreeArray;

     serializer.Serialize(Console.Out, f);
   }
}

설명

XML 문서에는 XML 요소의 계층 구조가 포함될 수 있습니다. 이러한 계층 구조를 나타내기 위해 배열 배열이 사용됩니다. 이러한 배열에서 각 인덱스는 계층 구조의 수준을 나타냅니다. 따라서 NestingLevel 이 속성은 배열 배열을 반환하는 XmlArrayItemAttribute 필드에 적용할 때만 사용됩니다.

특성을 적용할 때 특성을 설정 NestingLevel하여 특성에 영향을 미치는 계층 수준을 지정합니다. 첫 번째 인덱스의 값은 항상 0입니다. 따라서 값이 없는 NestingLevel 값을 첫 번째 배열 인덱스로 설정하는 NestingLevel XmlArrayItemAttribute 것은 선택 사항입니다. 후속 XmlArrayItemAttribute 개체에만 지정된 값(1, 2, 3 등)이 필요합니다 NestingLevel .

적용 대상