Create a dynamic hierarch menu with C # with XML

zhaozj2021-02-08  279

(Author: Green Apple studio compilation, 2001 at 11:35 on April 2)

From the exchange data in complex B2B transactions to provide a configuration file structure for the application, XML is very big in many ways! Since XML is constantly obtaining software support, we can fully expect: XML applications will continue to increase. This article describes such an application that uses XML to create a hierarchical menu system similar to the Windows Start menu, providing a more satisfactory web experience to end users. This app will use C #, XML, and Server-side Microsoft .NET Framework, create a DHTML structure, IE4 or higher browser to operate it and dynamically displayed on the client. Since we can quickly access the XML on the server, the XML can describe the relationship between the hierarchy, so it becomes the best choice for tag "Father / Sub Menu" data. (A three-tier menu system, you can change) In addition to learning how to create a menu application using XML, we also introduce the main XML class of the .NET framework, which is located in the System.xml collection. What is the .NET collection (Assembly) To use XML in the C # file, you must reference a specific namespace. One namespace in the .NET platform is used as an organizational system for a program component, which is important to solve the naming conflict, this is very like the namespace in XML. This XML-based menu system is created with the System.xml namespace located in the System.xml collection of SYSTEM.XML. .NET SDK is a collection of definitions: A collection is a collection of collection information of the type and resource, these classes and resources are used together, forming a logical unit, a "logical" DLL. A collection requires many physical files, such as interfaces, classes, resource files, etc., and created metadata about how files work together. Version and security information may also be included in the collection. There are many benefits of the collection, one is to use in the ASP.NET application without having to add a class identification number (CLSID) to the registration file with Regsvr32.exe. In this way, the collection of upgrades is as simple as the bin directory that copies the appropriate collection to a ASP.NET application. Now let's take a closer look at the classes built in the System.xml namespace and collection. If you have previously used Microsoft's MSXML3 digests, you will find that the classes in the SYSTEM.XML collection are quite simple. The menu application here uses only part of these major collection classes: XMLNode, XMLDocument, XMLNodeList, XMLNameDNodeMap, Documentnavigator, XMLTextReader, and XMLTextWriter. XMLDocument, XMLNodeList, and XMLNode classes are used to create a structure that passes the menu application that passes to the client browser. Load and decompose local or remote XML documents from the server in a secure thread-safe manner in a safe thread-safe. The XML tag established in a string can also be loaded or decomposed to create, mobile nodes, or cancel the movement of the node in one document. The XMLNodeList class allows us to list a collection of nodes to access a specific properties such as name, value, or namespace. Finally, the XMLNode class can be used to assign a specific node to an XMLNode object for verification in the XML document. The XMLNameDNodeMap class is used to enumerate the collection of properties in one element type selection. Documentnavigator, XMLTextReader, and XMLTextWriter classes provide additional features you need to use with XML. It is to be specifically described that Documentnavigator can be used to perform an XPath query that is included in the XSLT conversion.

The XMLTextReader class provides only Forward-Only, unabled access to the XML node, so that the XML node also takes effect on large XML documents. The XMLTextWriter class provides a quick, forward pointer model that implements the XML content to a stream or a file. The XML document used in the menu application is relatively small, so we can use Document Object Mode (DOM) to access different nodes in the XML document on the server side. When you break down a large XML document, you need to use only the forward model contained in the XMLTextReader class. The XML code menu application uses 3 XML documents: MenuItems.xml, MenuItems2.xml, and MenuItems3.xml, which are used to mark separate menu items. The XML processing and operation is done by a collection called Xmlmenus.dll, which is used by a server-side ASP.NET file CreateMenus.aspx. On the client's dynamic HTML (DHTML) content uses a laminated format table file and a JavaScript file, which is combined together with the graphic results of the start section of this article. We show part of the XML documentation used to mark a separate menu item in List 1. The main element in the document is named MenuItem, which can contain a name and hyperlink element as well as additional MenuiteM child elements. This relationship can be used to create a menu system that contains submenus, just like Windows's start menu. Since XML has already marked a layered relationship, you can walk between different elements: When you create a child node using XMLDocument, XMLNode, and XMLNodelist classes, we can repeatedly call the WalkTree () function to reverse the father / sub-relation. Other classes such as ArrayList and StreamWriter are used to classify the relevant menu into an array, and then write the generated menu structure into a file at the appropriate time. When the XMlmenus collection code begins with an XMLHierMenu namespace, then references System, System.xml, System.Collections and System.io namespace: use system; using system.xml; using system.collections; using system.io After this part of the code, you want to create 3 constructors. A constructor does not receive a variable, which is only initialized. The next constructor receives a custom path for an image file. The last constructor allows the output generated by the set generated to a file without not often refreshing the XML menu. The files generated by the last constructor can be static in an ASP.NET file instead of being generated at any time when requested in each web page. After the constructor, the CreateMenu () method begins, see the code in List 2, specifically. This method is responsible for the loading and parsing of the XML document, finds a root node, and then cycles between the child nodes of the root. If a child node itself has a subtock, call the walktree () method and passes these sub-nodes therebetween. If these child nodes have subtots, WalkTree () is called again. This process loops until no additional child nodes are disconnected. The code for the walktree () method can see List 3. At the same time that the WalkTree () method is called and the different nodes are analyzed, the MenuItem node is parsed, and the data from its hyperlink and the name node is placed in the array list. After the entire XML document is parsed, the contents of the array list are passed the page of the ASP.NET called and then written with the Response object. From this time, the client's JavaScript code starts to control the DHTML menu.

转载请注明原文地址:https://www.9cbs.com/read-503.html

New Post(0)