/// <summary> /// Method demonstrating the use of the GetHosts API call /// </summary> /// <param name="baseURL">the base URL of the API service</param> /// <param name="sld">SLD to use (e.g. enom of enom.com)</param> /// <param name="tld">TLD to use (e.g. com of enom.com)</param> /// <returns>List of <see cref="HostEntry"/> objects</returns> private static List <HostEntry> GetHosts(string baseURL, string sld, string tld) { List <HostEntry> hostList = new List <HostEntry>(); string result = string.Empty; // Append the necessary arguments string completeURL = baseURL + string.Format("&command=GetHosts&sld={0}&tld={1}", sld, tld); // Load the API results into an XmlDocument object var xmlDoc = new XmlDocument(); xmlDoc.Load(completeURL); // Determine if errors ocurred var errorCount = xmlDoc.SelectSingleNode("/interface-response/ErrCount").InnerText; // If no errors, display results if (errorCount.Trim() == "0") { XmlNodeList hosts = xmlDoc.SelectNodes("//host"); // Iterate the hosts returned and gether them // up into a collection of objects foreach (XmlNode host in hosts) { HostEntry entry = new HostEntry(); entry.Name = host.SelectSingleNode("name").InnerText; entry.RecordType = host.SelectSingleNode("type").InnerText; entry.Address = host.SelectSingleNode("address").InnerText; hostList.Add(entry); } } else { // There were errors, display them XmlNodeList errors = xmlDoc.SelectNodes("/interface-response/errors/*"); foreach (XmlNode node in errors) { Console.WriteLine("Error retrieving list: " + node.InnerText); } } return(hostList); }
/// <summary> /// Method demonstrating the use of the GetHosts API call /// </summary> /// <param name="baseURL">the base URL of the API service</param> /// <param name="sld">SLD to use (e.g. enom of enom.com)</param> /// <param name="tld">TLD to use (e.g. com of enom.com)</param> /// <returns>List of <see cref="HostEntry"/> objects</returns> private static List<HostEntry> GetHosts(string baseURL, string sld, string tld) { List<HostEntry> hostList = new List<HostEntry>(); string result = string.Empty; // Append the necessary arguments string completeURL = baseURL + string.Format("&command=GetHosts&sld={0}&tld={1}", sld, tld); // Load the API results into an XmlDocument object var xmlDoc = new XmlDocument(); xmlDoc.Load(completeURL); // Determine if errors ocurred var errorCount = xmlDoc.SelectSingleNode("/interface-response/ErrCount").InnerText; // If no errors, display results if (errorCount.Trim() == "0") { XmlNodeList hosts = xmlDoc.SelectNodes("//host"); // Iterate the hosts returned and gether them // up into a collection of objects foreach (XmlNode host in hosts) { HostEntry entry = new HostEntry(); entry.Name = host.SelectSingleNode("name").InnerText; entry.RecordType = host.SelectSingleNode("type").InnerText; entry.Address = host.SelectSingleNode("address").InnerText; hostList.Add(entry); } } else { // There were errors, display them XmlNodeList errors = xmlDoc.SelectNodes("/interface-response/errors/*"); foreach (XmlNode node in errors) { Console.WriteLine("Error retrieving list: " + node.InnerText); } } return hostList; }