Finally how to read from a XML Document, with this little script for a page.
use the following for c#
protected void Page_Load(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
DataSet mycountries = new DataSet();
mycountries.ReadXml(MapPath("text_xml.xml"));
rb.DataSource = mycountries;
rb.DataValueField = "value";
rb.DataTextField = "design";
rb.DataBind();
xmlDoc.Load(MapPath("text_xml.xml"));
XmlNodeList xmlnodelist = xmlDoc.DocumentElement.ChildNodes;
XmlNode xmlnode = xmlnodelist.Item(0);
int xmlcount = xmlnodelist.Count;
TextBox1.Text = xmlnode["design"].InnerText;
TextBox2.Text = xmlnode["value"].InnerText;
Body.Style.Add("background-color", xmlnode["backcolor"].InnerText);
XmlNode xmlnode2 = xmlnodelist.Item(1);
TextBox2.Text = xmlnode2["value"].InnerText;
}
protected void Button1_Click(object sender, EventArgs e)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(MapPath("text_xml.xml"));
XmlNodeList xmlnodelist2 = xmlDoc.DocumentElement.ChildNodes;
XmlNode xmlnode2 = xmlnodelist2.Item(1);
TextBox1.Text = xmlnode2["design"].InnerText;
Body.Style.Add("background-color", xmlnode2["backcolor"].InnerText);
Body.Style.Add("color", "white");
}
or in vb.net use:
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim xmlDoc As New XmlDocument
Dim mycountries = New DataSet
mycountries.ReadXml(MapPath("text_xml.xml"))
rb.DataSource = mycountries
rb.DataValueField = "value"
rb.DataTextField = "design"
rb.DataBind()
xmlDoc.Load(MapPath("text_xml.xml"))
Dim xmlnodelist As XmlNodeList = xmldoc.DocumentElement.ChildNodes
Dim xmlnode As XmlNode = xmlnodelist.Item(0)
TextBox1.Text = xmlnode("design").InnerText
TextBox2.Text = xmlnode("value").InnerText
Body.Style.Add("background-color", xmlnode("backcolor").InnerText)
Dim xmlnode2 As XmlNode = xmlnodelist.Item(1)
TextBox2.Text = xmlnode2("value").InnerText
End Sub
Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xmlDoc As New XmlDocument
xmlDoc.Load(MapPath("text_xml.xml"))
Dim xmlnodelist2 As XmlNodeList = xmlDoc.DocumentElement.ChildNodes
Dim xmlnode2 As XmlNode = XmlNodeList2.Item(1)
TextBox1.Text = xmlnode2("design").InnerText
Body.Style.Add("background-color", xmlnode2("backcolor").InnerText)
Body.Style.Add("color", "white")
End Sub
No comments:
Post a Comment