topical media & game development
mashup-amazon-07-07-02-AmazonRSS-sample-xml.aspx.cs / cs
Author: Francis A. Shanahan
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Xml;
public partial class sample_xml : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Response.Clear();
// Set the response type to XML
Response.ContentType = "text/xml";
// Create a new document
XmlDocument myXml = new XmlDocument();
// Create a new element node named "album"
XmlNode myAlbum = myXml.CreateNode(XmlNodeType.Element, "album", "");
// Create an attribute for this node, called "title" with a value of "BBC Sessions"
XmlAttribute albumName = myXml.CreateAttribute("title");
albumName.Value = "BBC Sessions";
// Add the attribute to the node
myAlbum.Attributes.Append(albumName);
// Add the album node to the document
myXml.AppendChild(myAlbum);
// Create some "song" nodes
XmlNode mySongA = myXml.CreateNode(XmlNodeType.Element, "song", "");
XmlNode mySongB = myXml.CreateNode(XmlNodeType.Element, "song", "");
XmlNode mySongC = myXml.CreateNode(XmlNodeType.Element, "song", "");
mySongA.InnerText = "Out on the Tiles";
mySongC.InnerText = "Achilles Last Stand";
// Add the child nodes this node
myAlbum.AppendChild(mySongA);
myAlbum.AppendChild(mySongB);
myAlbum.AppendChild(mySongC);
// Write out the XML document
Response.Write(AmazonUtility.GetStringFromXml(myXml));
Response.End();
}
}
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.