views:

22

answers:

1

Hi,

How can I use the returned XML from the reader in a xmltextreader?

            ' Create the web request  
        request = DirectCast(WebRequest.Create("https://mobilevikings.com/api/1.0/rest/mobilevikings/sim_balance.xml"), HttpWebRequest)

        ' Add authentication to request  
        request.Credentials = New NetworkCredential("username", "password")

        ' Get response  
        response = DirectCast(request.GetResponse(), HttpWebResponse)

        ' Get the response stream into a reader  
        reader = New StreamReader(response.GetResponseStream())

Thanks in advance,
Nathan.

A: 

You don't need to create new StreamReader, just use GetResponseStream

//Get the Response Stream from the URL 
Stream responseStream = response.GetResponseStream(); 

// Read the Response Stream using XmlTextReader 
XmlTextReader reader = new XmlTextReader(responseStream); 

//read through all the nodes
while(reader.Read())
{
  //find the item node and read its value
  if(reader.Name == "item")
  {
        Console.Write(reader.ReadString());
  }
}
volody