Export (0) Print
Expand All

XmlDocumentSchema Class

Represents the structure, or schema, of an XmlDocument. This class cannot be inherited.

System.Object
  System.Web.UI.Design.XmlDocumentSchema

Namespace:  System.Web.UI.Design
Assembly:  System.Design (in System.Design.dll)

[SecurityPermissionAttribute(SecurityAction.Demand, Flags = SecurityPermissionFlag.UnmanagedCode)]
public sealed class XmlDocumentSchema : IDataSourceSchema

The XmlDocumentSchema type exposes the following members.

  NameDescription
Public methodXmlDocumentSchemaCreates an instance of the XmlDocumentSchema class using a specified XmlDocument and an XPath string.
Top

  NameDescription
Public methodEquals(Object)Determines whether the specified object is equal to the current object. (Inherited from Object.)
Public methodGetHashCodeServes as the default hash function. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodGetViewsGets an array containing information about each child node starting at the node identified by the xPath parameter in the constructor, or each child node starting at the document root if the xPath parameter is empty.
Public methodToStringReturns a string that represents the current object. (Inherited from Object.)
Top

The XmlDocumentSchema class is used by custom control designer components to list the structural elements of an XML document at design time. Use the XmlDocumentSchema class to populate lists of document elements to allow users to select document elements in UI features at design time.

The following code example uses an XmlDocumentSchema object to display the structure of an XML document in a TreeView control.

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

.NET Framework

Supported in: 4.5, 4, 3.5, 3.0, 2.0

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Show:
© 2014 Microsoft