Recently, I used FLASH to call the XML generated by DataSet. I found that DataSet XML has a fixed format and there are no good methods on the Internet. So I wrote it for your reference.
Protected void Page_Load (object sender, EventArgs e)
{
TBLL. TSlide slidebll = new TBLL. TSlide ();
DataSet ds = slidebll. GetAllList ();
XmlDataDocument xdd = SetItemsCountAttribute (ds );
Response. Clear ();
Xdd. Save (Response. OutputStream );
Response. End ();
}
Private XmlDataDocument SetItemsCountAttribute (DataSet ds)
{
Try
{
XmlDataDocument xmlDoc;
Int ItemCount = 0;
Ds. DataSetName = strRootNodeName;
Ds. EnforceConstraints = false;
XmlDoc = new XmlDataDocument ();
XmlNode xmlDocNode = xmlDoc. CreateXmlDeclaration ("1.0", "UTF-8", null );
XmlDoc. AppendChild (xmlDocNode );
XmlNode viewer = xmlDoc. CreateElement ("viewer ");
XmlAttribute interval = xmlDoc. CreateAttribute ("interval ");
Interval. Value = "4000 ";
Viewer. Attributes. Append (interval );
Xmlattribute israndom = xmldoc. createattribute ("israndom ");
Israndom. value = "1 ";
Viewer. Attributes. append (israndom );
Xmldoc. appendchild (viewer );
For (INT I = 0; I <Ds. Tables [0]. Rows. Count; I ++)
{
Xmlnode item = xmldoc. createelement ("item ");
XmlAttribute title = xmlDoc. CreateAttribute ("title ");
Title. Value = ds. Tables [0]. Rows [I] ["Title"]. ToString ();
Item. Attributes. Append (title );
XmlAttribute img = xmlDoc. CreateAttribute ("img ");
Img. Value = ds. Tables [0]. Rows [I] ["ImgUrl"]. ToString ();
Item. Attributes. Append (img );
XmlAttribute url = xmlDoc. CreateAttribute ("url ");
Url. Value = ds. Tables [0]. Rows [I] ["LinkUrl"]. ToString ();
Item. Attributes. Append (url );
XmlAttribute target = xmlDoc. CreateAttribute ("target ");
Target. Value = "_ blank ";
Item. Attributes. Append (target );
Viewer. appendchild (item );
}
Return xmldoc;
}
Catch (exception E)
{
String strmsg = E. message;
Return NULL;
}
}