// (Remember that this XML file cannot be saved on the client. You can put it in a hiddenfile)
Function createxmls ()
{
VaR rowsarray = Document. All ('tbllist'). Rows; // obtain all rows in the table.
VaR oxml = new activexobject ("Microsoft. xmldom"); // create an XML Object
Oxml = Document. createelement ("data"); // create a "data" element <DATA> </data>
For (VAR I = 1; I <rowsarray. length; I ++)
{
If (rowsarray [I]. cells [1] = NULL | rowsarray [I]. cells [3] = NULL | rowsarray [0]. cells [2] = NULL) break;
Oitem = oxml. appendchild (document. createelement ("item"); // create an item element and use it as a child node of data
Itemid = oitem. appendchild (document. createelement ("Itemid"); // create the Itemid element and use it as a subnode of the item
Itemname = oitem. appendchild (document. createelement ("itemname"); "); // create the itemname element and use it as a subnode of the item
Itemtype = oitem. appendchild (document. createelement ("itemtype"); // create the itemtype element and use it as a subnode of the item
Itemid. appendchild (document. createtextnode (rowsarray [I]. cells [2]. innertext); // create a text node and use it as a subnode of Itemid
Itemname. appendchild (document. createtextnode (rowsarray [I]. cells [3]. innertext ));
Itemtype. appendchild (document. createtextnode (rowsarray [I]. cells [1]. innertext ));
}
// Rowsarray [I]. cells [2]. innertext: the value of innertext in the third column of the current row.
VaR hidvalue = Document. getelementbyid ("ctl00_contentplaceholder1_hidxmlstring ");
Hidvalue. value = oxml. outerhtml;
}
// * Innerhtml,... difference
Innerhtml sets or obtains the HTML in the start and end tags of an object.
Outerhtml sets or obtains the HTML format of the object and its content
Innertext sets or obtains the text in the object's start and end labels.
Outertext setting (including tags) or obtaining (excluding tags) the text of an object
Innertext and outertext are the same when reading and obtaining data, but when you set them, outertext will replace them with tags to the target text.
Firefox does not support innertext, but textcontent can be used as an alternative.
// Test
<Div id = "Div"> <font color = "green"> <H2> This Is A Div! </H2> </font> </div>
<Input name = "innerhtml" value = "innerhtml" type = "button" onclick = "alert (div. innerhtml); "> // Result:"> <font color = "green"> <H2> This Is A Div! </H2> </font>
<Input name = "outerhtml" value = "outerhtml" type = "button" onclick = "alert (div. outerhtml); "> // result: <Div id =" Div "> <font color =" green "> <H2> This Is A Div! </H2> </font> </div>
<Input name = "innertext" value = "innertext" type = "button" onclick = "alert (Div. innertext);">
<Input name = "outertext" value = "outertext" type = "button" onclick = "alert (Div. outertext);">
*/
// The created XML
<DATA>
<Item>
<Itemid> 1 </Itemid>
<Itemname> FF </itemname>
<Itemtype> 1 </itemtype>
<Item>
<Item>
<Itemid> 1 </Itemid>
<Itemname> FF </itemname>
<Itemtype> 1 </itemtype>
<Item>
.......
</Data>
// Save the server-side read XML to the database:
Protected void savexmltodatabase ()
{
String xmlstring = This. hidxmlstring. value. Trim (); // retrieve XML from hiddenbutton
Xmldocument Doc = new xmldocument ();
Doc. loadxml (xmlstring); // load it into an XML file
Xmlnodelist rootlist = Doc. selectsinglenode ("data"). childnodes;
Dictionary promotion = New Dictionary ();
Bool flag = false;
Foreach (xmlnode xfnode in rootlist)
{
Xmlelement xe1 = (xmlelement) xfnode;
Xmlnodelist xitemlist = xe1.childnodes; // continue to obtain all the child nodes of the Xe subnode
Foreach (xmlnode xnnode in xitemlist)
{
Xmlelement Xe = (xmlelement) xnnode;
If (Xe. Name. tolower () = "Itemid ")
{
Promotion ["promo_rank"] = Xe. innertext;
}
If (Xe. Name. tolower () = "itemname ")
{
Promotion ["promo_name"] = Xe. innertext;
}
If (Xe. Name. tolower () = "itemtype ")
{
Promotion ["promo_type"] = Xe. innertext;
}
}
Flag = bllsales. addorupdatepromotionbyrank (promotion, enums. dataaccessmode. Update );
}
}