Wednesday, April 22, 2009

Browse child node of Amazon Parend Nodes using amazon webservice , asp.net 2.0, C# etc.


Browse child node of Amazon Parend Nodes using amazon webservice , asp.net 2.0, C# etc.

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 Default2 : System.Web.UI.Page
{
    string strname;
    protected void Page_Load(object sender, EventArgs e)
    {
        XmlDocument doc = new XmlDocument();

        if (Request["nodeid"] == null)
        {
            doc.Load("http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=YouraccessID&Operation=BrowseNodeLookup&BrowseNodeId=3375251&ResponseGroup=BrowseNodeInfo");
        }
        else
        {
            doc.Load("http://ecs.amazonaws.com/onca/xml?Service=AWSECommerceService&AWSAccessKeyId=YouraccessID&Operation=BrowseNodeLookup&BrowseNodeId=" + Request["nodeid"] + "&ResponseGroup=BrowseNodeInfo");
       
        }
       
        XmlNodeList lstIsValid = doc.GetElementsByTagName("IsValid");
        if (lstIsValid.Count > 0 && lstIsValid[0].InnerXml == "True")
        {
            XmlNodeList lstItems = doc.GetElementsByTagName("Children");
            if (lstItems.Count > 0)
            {
               
                XmlNode nItem = lstItems[0];
                foreach (XmlNode nChild in nItem.ChildNodes)
                {
                
                    if (nChild.Name == "BrowseNode") //string compare !
                    {
          
                        strname = strname + "<a  href=Default2.aspx?nodeid=" + nChild["BrowseNodeId"].InnerText + ">" + nChild["Name"].InnerText + "</a><br/>";
                       
                    }
                   
                }
                Response.Write(strname);
       
            }
        }
    }
}

No comments: