locked
I want to show Raw XML code to aspx web page with design RRS feed

  • Question

  • User624488380 posted

    Hi, 

    Recently i implement a api from WHOISAPI. But i am receiving raw xml data which is showing in my webapps as raw one.

    Here is the screeshot please see: CLICK HERE

    I want to show it as tree base. OR in any format that can ready easily as a webpage Like this. 

    Click here : Click Here

    That is my code in web apps

    protected void btnScan_Click(object sender, EventArgs e)
    {
    try
    {
    DOMAIN = txtUrl.Text;
    string url = "http://www.whoisxmlapi.com/whoisserver/WhoisService?"
    + $"domainName={DOMAIN}&username={USERNAME}"
    + $"&password={PASSWORD}";
    string whoisData = string.Empty;

    HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
    //StreamReader reader=StreamReader.Null;
    using (HttpWebResponse response = (HttpWebResponse)req.GetResponse())
    using (Stream stream = response.GetResponseStream())
    using (StreamReader reader = new StreamReader(stream))
    {
    whoisData = reader.ReadToEnd();
    }
    // reader = new StreamReader(stream);
    //XmlReader xmlreader = XmlReader.Create(reader);
    //while (xmlreader.Read())
    //{
    // whoisData=xmlreader.Value;
    //}
    //xmlreader.Close();
    pResult.InnerText = whoisData;
    }
    catch (Exception ex)
    {

    throw;
    }
    }
    }

    Sunday, April 21, 2019 3:12 PM

Answers

  • User-893317190 posted

    Hi samprit chakraborty,

    I have visisted whoisxml api and use this link's xml as a reference.

    https://whoisapi.whoisxmlapi.com/whois/google.com?format=XML

    And I find all the data could be found in the rowText node, so if you want to show it in an organized way, you could refer to the code below.

     XElement element  =  XElement.Load(Server.MapPath("/xmlDemo/domainData.xml"));
              IEnumerable<XElement> xElements  =  element.Descendants("rawText");
                StringBuilder stringBuilder = new StringBuilder();
                foreach (XElement item in xElements)
                {
                   stringBuilder.Append( item.Value.Replace("\n", "<br/>"));
                }
                Response.Write(stringBuilder.ToString());

    The result.

    If you want a single node's value , you could refer to the link below.For example, if you want to get registrant node's organization value , you could write

    //             < registrant >
                //    < organization > Google LLC </ organization >
    
                //       < state > CA </ state >
    
                //       < country > UNITED STATES </ country >
    
                //          < countryCode > US </ countryCode >
    
                //          < rawText > Registrant Organization: Google LLC
                //Registrant State/ Province: CA
                // Registrant Country: US </ rawText >
    
                //   </ registrant >
               string orgainization =  element.Descendants("registrant").First().Element("organization").Value;

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 2, 2019 5:54 AM

All replies

  • User-893317190 posted

    Hi samprit chakraborty,

    The simplest way to view xml data in browser is to use browser's build-in support for showing xml.

    Below is a simple demo.

      protected void Button1_Click(object sender, EventArgs e)
            {
                WebRequest request = WebRequest.Create("http://www.whoisxmlapi.com/whoisserver/WhoisService");
    
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
    
                Stream dataStream = response.GetResponseStream();
        
                StreamReader reader = new StreamReader(dataStream);
            
                string responseFromServer = reader.ReadToEnd();
             
                Response.Clear();  // remove other data
                Response.ContentType = "text/xml";// set content type to text/xml to show xml data
                Response.Write(responseFromServer); // write the xml
                Response.End(); // end the response
              
                reader.Close();
                dataStream.Close();
                response.Close();
    
    
            }

    The result.

    Best regards,

    Ackerly Xu

    Tuesday, April 23, 2019 3:27 AM
  • User624488380 posted

    Hi,

    Thanks for your awesome support. I want to show the XML data within a table . Like this : http://prntscr.com/nftovx 

    How can i do it ?  

    Tuesday, April 23, 2019 2:56 PM
  • User-893317190 posted

    Hi samprit chakraborty,

    It depends on the structure of your xml.

    You could retrieve data trough XElement or XmlDocument api.

    For example  , about XElement, you could

       
                WebRequest request = WebRequest.Create("http://www.whoisxmlapi.com/whoisserver/WhoisService");
               
           
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
       
        
                Stream dataStream = response.GetResponseStream();
        
                StreamReader reader = new StreamReader(dataStream);
            
                string responseFromServer = reader.ReadToEnd();
    
              XElement element =   XElement.Load(new StringReader(responseFromServer));
              Response.Write(  element.Element("msg").Value);
                element.Elements("msg").ToList();
                
              
                reader.Close();
                dataStream.Close();
                response.Close();
    

    element.Element get single element with the specified tag name, and then you could get the text in it through Value property.

    element.Elements get  all element with the specified tag name, and then you could get all element in it and then get  their values.

    You could then show these values in a gridview.

    Best regards,

    Ackerly Xu

    Wednesday, April 24, 2019 1:58 AM
  • User624488380 posted

    Hi, 

    The Problem briefly discussed in video please have a look :( actually i am receiving the data perfectly but cant show it in my webpage in organized way

    Video Link : https://youtu.be/p756AUAQocw

    Monday, April 29, 2019 6:24 PM
  • User624488380 posted

    can u please code me in details please cause i am getting unhandled situation while trying your code. Please do me a favour just implement the api create a webform and pass the data into table and help me with that code 

    Monday, April 29, 2019 7:13 PM
  • User2053451246 posted

    Please do me a favour just implement the api create a webform and pass the data into table and help me with that code 
    Wow.  Just wow.  And how much per hour are you offering?  Aren't you being paid for this?

    Monday, April 29, 2019 7:18 PM
  • User624488380 posted

    i am making it as my final year project for graduation. Basically, i am a network engineer. but university authority force me to do software development. So thats why i am newbie in Dot net platform. 

    Tuesday, April 30, 2019 5:49 PM
  • User-893317190 posted

    Hi samprit chakraborty,

    I have visisted whoisxml api and use this link's xml as a reference.

    https://whoisapi.whoisxmlapi.com/whois/google.com?format=XML

    And I find all the data could be found in the rowText node, so if you want to show it in an organized way, you could refer to the code below.

     XElement element  =  XElement.Load(Server.MapPath("/xmlDemo/domainData.xml"));
              IEnumerable<XElement> xElements  =  element.Descendants("rawText");
                StringBuilder stringBuilder = new StringBuilder();
                foreach (XElement item in xElements)
                {
                   stringBuilder.Append( item.Value.Replace("\n", "<br/>"));
                }
                Response.Write(stringBuilder.ToString());

    The result.

    If you want a single node's value , you could refer to the link below.For example, if you want to get registrant node's organization value , you could write

    //             < registrant >
                //    < organization > Google LLC </ organization >
    
                //       < state > CA </ state >
    
                //       < country > UNITED STATES </ country >
    
                //          < countryCode > US </ countryCode >
    
                //          < rawText > Registrant Organization: Google LLC
                //Registrant State/ Province: CA
                // Registrant Country: US </ rawText >
    
                //   </ registrant >
               string orgainization =  element.Descendants("registrant").First().Element("organization").Value;

    Best regards,

    Ackerly Xu

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, May 2, 2019 5:54 AM
  • User624488380 posted

    Thanks a lot man ! finaly i get my answer. All the best bro ! You are really helpfull  ! Thanks to all of you guys. 

    Thursday, May 2, 2019 5:26 PM