XML generated by ASP. NET is a common function. XML can transmit more data and information. The XML generated by ASP. NET starts from the business logic layer, data access layer, and presentation layer, and is presented as code.
1. business logic layer:
- public DataSet ABCData()
- {
- DataBase db = new DataBase();
- string sql = "select * from products where products_Year='2008'";
- DataSet ds = db.GetDataSet(sql);
- return ds;
- }
Note:
Produts_Id products_Name products_Quantity products_Year
38 AAA 7649 2008
39 BBB 4567 2008
40 CCC 6410 2008
2. Data access layer:
3. Presentation Layer:
- Protected void Page_Load (object sender, EventArgs e)
- {
- DataBindDatabind=NewDataBind ();
- DataSetDs=Databind. ABCData ();
-
- StringPlot_type="CategorizedVertical";
- XmlDocumentDoc=NewXmlDocument ();
- XmlElementNode=Doc. CreateElement ("anychart"); // create an anychart Node
- Doc. AppendChild (Node );
-
- XmlElementNode1=Doc. CreateElement ("charts"); // create the node anychart subnode charts
- Doc. DocumentElement. AppendChild (Node1 );
-
- XmlElementNode2=Doc. CreateElement ("chart"); // create a node charts subnode chart
- Node2.SetAttribute ("plot_type", plot_type); // Add the plot_type attribute to the node chart
- Node1.AppendChild (Node2 );
-
- XmlElementNode3=Doc. CreateElement ("data"); // create the first subnode data of the node chart
- Node2.AppendChild (Node3 );
-
- XmlElementNode4=Doc. CreateElement ("chart_settings"); // create the second subnode chart_settings of the node chart.
- Node2.AppendChild (Node4 );
-
- XmlElementNode5=Doc. CreateElement ("series"); // create a node data subnode series
- Node5.SetAttribute ("name", "Year 2003"); // Add the first attribute name for the series Node
- Node5.SetAttribute ("type", "Bar"); // Add the second attribute type for the series Node
- Node3.AppendChild (Node5 );
- For (intI=1; I<= 3; I ++)
- {
- XmlElementNode13=Doc. CreateElement ("point"); // create a subnode point in node series
- Node13.SetAttribute ("name", ds. tables [0]. rows [I-1] ["products_Name"]. toString (); // Add the attribute name for the point node and set ds. in Tables [0], the products_Name column is extracted row by row and assigned to the attribute name.
- Node13.SetAttribute ("y", ds. tables [0]. rows [I-1] ["products_Quantity"]. toString (); // Add attribute y for the point node and set ds. in Tables [0], a column of products_Quantity data is retrieved row by row and assigned to attribute y.
- Node5.AppendChild (Node13 );
- }
-
- XmlElementNode6=Doc. CreateElement ("title ");
- Node4.AppendChild (Node6 );
-
- XmlElementNode7=Doc. CreateElement ("axes ");
- Node4.AppendChild (Node7 );
-
- XmlElementNode8=Doc. CreateElement ("y_axis ");
- Node7.AppendChild (Node8 );
-
- XmlElementNode9=Doc. CreateElement ("x_axis ");
- Node7.AppendChild (Node9 );
-
- XmlElementNode10=Doc. CreateElement ("title ");
- Node10.InnerText="Sales"; // Assign the Sales value to the node title
- Node8.AppendChild (Node10 );
-
- XmlElementNode11=Doc. CreateElement ("title ");
- Node11.InnerText="Retail Channel";
- Node9.AppendChild (Node11 );
-
- XmlElementNode12=Doc. CreateElement ("text ");
- Node12.InnerText="Sales";
- Node6.AppendChild (Node12 );
- Doc. Save (Server. MapPath ("test. xml"); // Save the xml
- }
4. generated xml:
- <Anychart>
- <Charts>
- <Chart Plot_type="CategorizedVertical">
- <Data>
- <Series Name=& Quot; Year 2003 & quot" Type="Bar">
- <Point Name="AAA" Y="7649" />
- <Point Name="BBB" Y="4567" />
- <Point Name="CCC" Y="6410" />
- </Series>
- </Data>
- <Chart_settings>
- <Title>
- <Text>Sales<Text>
- </Title>
- <Axes>
- <Y_axis>
- <Title>Sales</Title>
- </Y_axis>
- <X_axis>
- <Title>Retail Channel</Title>
- </X_axis>
- </Axes>
- </Chart_settings>
- </Chart>
- </Charts>
- </Anychart>
Some methods for generating XML in ASP. NET are introduced here.
Original article title: XML with complex layers generated by ASP. NET
Link: http://www.cnblogs.com/jiaojiaojojo/archive/2009/09/04/1559963.html
- In-depth research on Repeater controls: Maximum Flexibility
- Getting started with DataList controls
- Exploring the operation mechanism of the DataGrid Web Control
- Discuss the similarity between ASP. NET data Web controls
- Transformation from traditional ASP to ASP. NET: Understanding controls