using System.Xml.Linq;protected void Button1_Click(object sender, EventArgs e){XDocument doc = new XDocument();XElement projectElement = new XElement("Project", new XAttribute("ProjectName", "xxx"), new XAttribute("ProjectDescription", "xxx"), new XAttribute("DateStart", "xxx"), new XAttribute("DateEnd", "xxx") );doc.Add(projectElement);for (int i = 0; i < 5; i++){projectElement.Add(new XElement("Property", new XAttribute("PropertyName", "PropertyName" + i), new XAttribute("PropertyValue", "PropertyValue" + i) ));}this.lbl.Text = Server.HtmlEncode(doc.ToString());this.lbl.DataBind();}
will produce xml that looks like this
<Project ProjectName="xxx" ProjectDescription="xxx" DateStart="xxx" DateEnd="xxx" ><Property PropertyName="PropertyName0" PropertyValue="PropertyValue0" /><Property PropertyName="PropertyName1" PropertyValue="PropertyValue1" /><Property PropertyName="PropertyName2" PropertyValue="PropertyValue2" /><Property PropertyName="PropertyName3" PropertyValue="PropertyValue3" /><Property PropertyName="PropertyName4" PropertyValue="PropertyValue4" /></Project>
No comments:
Post a Comment