locked
Read XML String RRS feed

  • Question

  • User1076264835 posted

    Hi All,

    I using HttpWebRequest to request XML String from the URL.

    URLStr = "http://example.com/test/"
    Dim webRequest As HttpWebRequest = CType(HttpWebRequest.Create(URLStr), HttpWebRequest) Using response As HttpWebResponse = CType(webRequest.GetResponse(), HttpWebResponse) Dim dataStream As Stream = response.GetResponseStream() Dim reader As New StreamReader(dataStream) Dim status As String = reader.ReadToEnd() 'XML Result is assign to status variable. reader.Close() response.Close() dataStream.Close() End Using

    My problem is, how can I read the value for the each parameter in that XML String?

    <?xml version="1.0" encoding="UTF-8"?>
    <results>
    	<result>
    		<status>0</status>
    		<id>033081473432630432</id>
    	</result>
    </results>
    Thursday, August 15, 2013 12:13 AM

Answers

  • User289622470 posted

    Hi,

     

       You can use following code to read throuh the xml string available in stream

     

       XmlTextReader xmlreader = null;

      xmlreader = new XmlTextReader (reader);

      while (xmlreader.Read())

    {    

    switch (xmlreader.NodeType)    

    {        

    case XmlNodeType.Element:

    // The node is an Element.            

    break;  

    case XmlNodeType.Text:

    //Process text           

    break;  

    case XmlNodeType. EndElement:

    //process end element

    break;    

     }

    }

     

    Thanks,

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, August 15, 2013 12:38 AM