Ce sujet n'a pas encore été évalué - Évaluez ce sujet

XmlArrayItemAttribute.NestingLevel, propriété

Obtient ou définit le niveau dans une hiérarchie d'éléments XML affectés par XmlArrayItemAttribute.

Espace de noms : System.Xml.Serialization
Assembly : System.Xml (dans system.xml.dll)

public int NestingLevel { get; set; }
/** @property */
public int get_NestingLevel ()

/** @property */
public void set_NestingLevel (int value)

public function get NestingLevel () : int

public function set NestingLevel (value : int)

Valeur de la propriété

Index de base zéro d'un ensemble d'index dans un tableau de tableaux.

Un document XML peut contenir des éléments XML situés à des niveaux hiérarchiques différents. Il utilise un tableau de tableaux pour représenter cette hiérarchie. Dans un tel tableau, chaque index représente un niveau dans la hiérarchie. Par conséquent, la propriété NestingLevel n'est utilisée que lors de l'application d'un XmlArrayItemAttribute à un champ qui retourne un tableau de tableaux.

Lorsque vous appliquez l'attribut, pour spécifier le niveau hiérarchique qu'il affecte, définissez NestingLevel. Le premier index a toujours une valeur égale à 0 ; il n'est donc pas obligatoire de définir son niveau NestingLevel ; un XmlArrayItemAttribute sans valeur NestingLevel s'applique au premier index du tableau. Seuls les objets XmlArrayItemAttribute suivants nécessitent des valeurs NestingLevel spécifiées (1, 2, 3, etc..).

L'exemple suivant applique trois attributs XmlArrayItemAttribute à un ensemble de tableaux. Pour spécifier à quel tableau chaque attribut s'applique, la propriété NestingLevel est définie à l'index des tableaux.

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);
   }
}

#using <mscorlib.dll>
#using <System.Xml.dll>
using namespace System;
using namespace System::Xml;
using namespace System::Xml::Serialization;
using namespace System::IO;

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

public __gc class Test{
public:
   static void main(){
      Test* t = new Test();
      t->SerializeObject(S"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]{S"One"};
      myTreeArray[0]=myBranchArray1;

      String* myBranchArray2[][] = new String*[][2];
      myBranchArray2[0]=new String*[2]{S"One",S"Two"};
      myBranchArray2[1]=new String*[3]{S"One",S"Two",S"Three"};
      myTreeArray[1]=myBranchArray2;
   
      f->TreeArray=myTreeArray;

      serializer->Serialize(Console::Out, f);
   }
};

int main(){
   Test::main();
}

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile pour Pocket PC, Windows Mobile pour Smartphone, Windows Server 2003, Windows XP Édition Media Center, Windows XP Professionnel Édition x64, Windows XP SP2, Windows XP Starter Edition

Le .NET Framework ne prend pas en charge toutes les versions de chaque plate-forme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise.

.NET Framework

Prise en charge dans : 2.0, 1.1, 1.0

.NET Compact Framework

Prise en charge dans : 2.0, 1.0
Cela vous a-t-il été utile ?
(1500 caractères restants)

Ajouts de la communauté

AJOUTER
© 2013 Microsoft. Tous droits réservés.