XmlDocumentSchema Classe

Définition

Représente la structure, ou schéma, d'un XmlDocument. Cette classe ne peut pas être héritée.

public ref class XmlDocumentSchema sealed : System::Web::UI::Design::IDataSourceSchema
public sealed class XmlDocumentSchema : System.Web.UI.Design.IDataSourceSchema
type XmlDocumentSchema = class
    interface IDataSourceSchema
Public NotInheritable Class XmlDocumentSchema
Implements IDataSourceSchema
Héritage
XmlDocumentSchema
Implémente

Exemples

L’exemple de code suivant utilise un XmlDocumentSchema objet pour afficher la structure d’un document XML dans un TreeView contrôle.

// This method fills a TreeView Web control from an XML file.
public void FillTreeView(TreeView treeVw, string fileName)
{
    // Get a reference to the current HttpContext
    HttpContext currentContext = HttpContext.Current;
    int i, j, k;
    TreeNode CurNode, NewNode;

    // Create and load an XML document
    XmlDocument XDoc = new XmlDocument();
    XDoc.Load(currentContext.Server.MapPath(fileName));

    // Get a map of the XML Document
    XmlDocumentSchema xSchema = new XmlDocumentSchema(XDoc, "");

    // Get a list of the root child views
    IDataSourceViewSchema[] RootViews = xSchema.GetViews();

    // Add each child to the TreeView
    for (i = 0; i < RootViews.Length; i++)
    {
        NewNode = new TreeNode(RootViews[i].Name);
        treeVw.Nodes.Add(NewNode);
        CurNode = treeVw.Nodes[i];

        // Get a list of children of this child
        IDataSourceViewSchema[] ChildViews = RootViews[i].GetChildren();
        // Add each child to the child node of the TreeView
        for (j = 0; j < ChildViews.Length; j++)
        {
            NewNode = new TreeNode(ChildViews[j].Name);
            CurNode.ChildNodes.Add(NewNode);
            CurNode = CurNode.ChildNodes[j];

            // Get a list of children of this child
            IDataSourceViewSchema[] ChildVws = ChildViews[j].GetChildren();
            // Add each child to the child node
            for (k = 0; k < ChildVws.Length; k++)
            {
                NewNode = new TreeNode(ChildVws[k].Name);
                CurNode.ChildNodes.Add(NewNode);
            }
            // Select the parent of the current child
            CurNode = CurNode.Parent;
        }
        // Select the parent of the current child
        CurNode = CurNode.Parent;
    }
}
Imports System.Xml
Imports System.Web
Imports System.Web.UI.WebControls
Imports System.Web.UI.Design

Public Class XmlDocumentSchemaSample

    ' This method fills a TreeView Web control from an XML file.
    Public Sub FillTreeView(ByVal treeVw As TreeView, ByVal fileName As String)
        ' Get a reference to the current HttpContext
        Dim currentContext As HttpContext = HttpContext.Current
        Dim i, j, k As Integer
        Dim CurNode, NewNode As TreeNode

        ' Create and load an XML document
        Dim XDoc As New XmlDocument()
        XDoc.Load(currentContext.Server.MapPath(fileName))

        ' Get a map of the XML Document
        Dim xSchema As New XmlDocumentSchema(XDoc, "")

        ' Get a list of the root child views
        Dim RootViews As IDataSourceViewSchema() = xSchema.GetViews()

        ' Add each child to the TreeView
        For i = 0 To RootViews.Length - 1
            NewNode = New TreeNode(RootViews(i).Name)
            treeVw.Nodes.Add(NewNode)
            CurNode = treeVw.Nodes(i)

            ' Get a list of children of this child
            Dim ChildViews As IDataSourceViewSchema() = RootViews(i).GetChildren()

            ' Add each child to the child node of the TreeView
            For j = 0 To ChildViews.Length - 1
                NewNode = New TreeNode(ChildViews(j).Name)
                CurNode.ChildNodes.Add(NewNode)
                CurNode = CurNode.ChildNodes(j)

                ' Get a list of children of this child
                Dim ChildVws As IDataSourceViewSchema() = ChildViews(j).GetChildren()
                ' Add each child to the child node
                For k = 0 To ChildVws.Length - 1
                    NewNode = New TreeNode(ChildVws(k).Name)
                    CurNode.ChildNodes.Add(NewNode)
                Next
                ' Select the parent of the current child
                CurNode = CurNode.Parent
            Next
            ' Select the parent of the current child
            CurNode = CurNode.Parent
        Next
    End Sub
End Class

Remarques

La XmlDocumentSchema classe est utilisée par les composants du concepteur de contrôles personnalisés pour répertorier les éléments structurels d’un document XML au moment du design. Utilisez la classe XmlDocumentSchema pour remplir des listes d’éléments de document pour permettre aux utilisateurs de sélectionner des éléments de document dans les fonctionnalités de l’interface utilisateur au moment du design.

Constructeurs

XmlDocumentSchema(XmlDocument, String)

Crée une instance de la classe XmlDocumentSchema à l'aide d'un XmlDocument spécifié et d'une chaîne XPath.

Méthodes

Equals(Object)

Détermine si l'objet spécifié est égal à l'objet actuel.

(Hérité de Object)
GetHashCode()

Fait office de fonction de hachage par défaut.

(Hérité de Object)
GetType()

Obtient le Type de l'instance actuelle.

(Hérité de Object)
GetViews()

Obtient un tableau contenant des informations relatives à chaque nœud enfant, en commençant par le nœud identifié par le paramètre xPath dans le constructeur ou en commençant par la racine du document si le paramètre xPath est vide.

MemberwiseClone()

Crée une copie superficielle du Object actuel.

(Hérité de Object)
ToString()

Retourne une chaîne qui représente l'objet actuel.

(Hérité de Object)

S’applique à

Voir aussi