Application of XML to custom controls under. NET Platform (2)

Source: Internet
Author: User
Tags add empty net string version xmlns
xml| Control  The second step is to add XML attributes

Note that any XML document is best validated before it is processed, and there are generally two important ways to provide validation. The first is to provide a DTD (document type definition), in fact, let the user provide the instruction set, and then in the XML document when loading the validity analysis, to see whether there are invalid instructions, simply to create a compilation environment; the other is to provide a so-called schema. It works exactly like a DTD. , it is better than a DTD in its presentation, because it is an XML document itself. Here I take the form of a schema, and of course, the reader can replace it with interest by asking the appropriate DTD version. The following lists the schema's code for controls and Topmenu objects, and if you want to see the detailed code for that document, see Code. doc.

MENU.XDR:





£

menus schema used to validate Menu.xml

£









£





















£





















£





















£











£

£

If you are familiar with HTML, believe that the above code even if it has not been contacted before should be clear, in. XDR, there are two objects, one is the element, with the prefix ElementType to define, the other is the corresponding attribute of the element, prefixed with Atttibutetpye, After the two objects are defined, they are instantiated, with the corresponding prefixes of element and atttibute, and then you can use both of the objects that have already been instantiated, as in HTML , , , , and so on.

For a clearer description of the above code, we give an example here, believe that readers at a glance:











£


After creating the XML document, you will read the XML document in the program, if you use Microsoft's Vs.net platform development, we recommend that you can use XmlTextReader to read the relevant information, details can be consulted on MSDN.

The third step: using the control

The menu control is created and is now used under the. NET Platform. You first compile the control under the Vs.net platform, and you can use it if the compilation succeeds. Using a. NET custom control is similar to using a generic ActiveX control. Start the widget box underneath the Vs.net platform (you can right-click on the toolbar to get it), note that we are making a COM component instead of a asp.net component, so from this point it is essentially different from the COM component, through B The Rowse button can select the corresponding DLL file for the control and add it to your project. Below you also need to add the following code in your program code (other code slightly)

using Your name space; (A)

You should also add the declaration of the control in behind code (B)

In fact, whether the code in a or the description of B, can be automatically generated by the Vs.net platform, if the use of other platforms and do not support the automatic addition of such code, you can manually add. After you've added it, you can use it with other controls. And all the public member variables in the control class code, functions correspond to the properties and methods of the control.

What needs to be specified here is that the control must provide two properties, that is Xmlstream and xmlfile, if the user has made the control's XML file (which describes the control's data), or has already written an XML code, You can pass code and files to Xmlstream and xmlfile, and the daemon (that is, the DLL file) reads XML data by invoking some XML readers such as XmlTextReader, which enables the control to support XML properties. It also enhances the portability and versatility of the control.

This paper mainly discusses the application of XML in the control production of the. NET platform, and from the above example, we can see that XML has its unique advantages in data integration and processing, if your project involves data processing and cross-platform problems, you can consider applying XML.



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.