ASP.NET creates a web component based on XML dynamics
(One)
Author: Li Tieshuai
Summary Time The author needs to dynamically create a web component in the development. This thought is a small thing. Who knows when it is easy to do. There is still a little problem in it. Below the author introduces you how to dynamically create and use web components, I hope to provide a little help to friends who do similar work.
First, program ideas
The program is mainly divided into three parts:
1. The program is to determine the number of web components that need to be created according to the data information in the XML.
2, dynamically create a web component.
3. Use a dynamically created web component.
These 2 and 3 are the parties that the author should focus on.
The author is described in accordance with these three partial combined programs (Take C # as an example).
Second, read the XML file
Reading XML files have a detailed description in many materials, and it is believed that many friends have already mastered their technology. However, in order to ensure the integrity of the article, the author still has to repeat a few words. Friends who are more harmful, can be skilled.
The XML file sharing to be read in the author program is as follows:
Config.xml
XML Version = "1.0"?>
Iplink>
Iplink>
...
Root>
The program that reads the XML file is as follows:
protected void readconfig ()
{
Try
{
System.xml.xmldocument mxmldoc = new system.xml.xmldocument ();
MXMLDoc.Load (Server.MAppath);
Nettype = mxmldoc.selectnodes ("// root / nettype") [0] .innertext; totalnum = int.parse ("// root / totalnum") [0] .innerText);
// read the number of columns
Cells = int.parse ("// root / cells") [0] .innerText);
XMLNodelist Mxmlnodes = mxmldoc.selectnodes ("// root / iplink");
Foreach (XMLNode iPlinkChildlNode in mxmlnodes)
{
// Get the serial number
Int iCount = int.parse (iPlinkChildlNode.childNodes [2] .INNNERTEXT);
/ / According to the serial number, place the name of the measurement point in the corresponding position corresponding to the name array.
NameStr [iCount] = iPlinkChildlNode.childNodes [0] .innertext;
/ / According to the serial number, put the IP of the measuring point into the corresponding position of the IP array.
Ipstr [iCount] = iPlinkChildlnode.childNodes [1] .innertext;
}
Catch
{
ErrMessage.innerhtml = "