ASP.NET is created and used in XML dynamics and uses web components (1)

zhaozj2021-02-16  53

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

Net

6

2

Site 1

192.8.198.1

1

Site 2

192.8.198.2

2

...

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 = "

You cannot read the configuration file, the possible error is
" " 1, the configuration file does not exist
"

"2, the configuration file content is damaged"

" ";

}

}

Elements such as non-child nodes in XML in the program

Net

Use the following statement to read directly.

MXMLDoc.selectNodes ("// root / nettype") [0] .innertext;

For elements with children such as:

Site 1

192.8.198.1

1

To use the statement to read it.

Iplinkchildlnode.childnodes [n] .innertext

Where [N] in ChildNodes [N] is the serial number, child node of the child node

Site 1

The serial number should be [0].

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

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.034, SQL: 9