How to read XML data from a URL by using vb.NET and save

后端 未结 3 1811
再見小時候
再見小時候 2020-12-21 11:47

Friends, I am able to get XML file by sing bytes, perhaps which is getting some problem. Can u suggest me alternate method to do the same thing to save XML file?

<         


        
相关标签:
3条回答
  • 2020-12-21 12:04

    Consider using XMLTextReader. This example just loads the entire XML into a string, but obviously you could write it to a file instead:

        Dim strUrl As String = "http://xyz.com"
        Dim reader As XmlTextReader = New XmlTextReader(strUrl)
        Dim output as String
    
        Do While (reader.Read())
            Select Case reader.NodeType
                Case XmlNodeType.Element 
    
                    Output = Output + "<" + reader.Name
    
                    If reader.HasAttributes Then 
                        While reader.MoveToNextAttribute()
                            Output = Output + " {0}='{1}'", reader.Name, reader.Value)
                        End While
                    End If
                    Output = Output + ">"
                Case XmlNodeType.Text
                    Output = Output + reader.Value
                Case XmlNodeType.EndElement
                    Output = Output + "</" + reader.Name + ">"
            End Select
        Loop
    
    0 讨论(0)
  • 2020-12-21 12:15

    Why not just use the WebClient class and its DownloadFile method?? Seems a lot easier....

    This is in C#, but you should have no trouble converting that to VB.NET:

    WebClient wc = new WebClient();
    wc.DownloadFile("http://xyz", @"C:\getxml.xml");
    

    and you're done!

    Marc

    0 讨论(0)
  • 2020-12-21 12:21

    What if the service is sending the request to our URL? How do I adjust this to read the http stream they send? Having such a hard time... (Should I do a separate thread? Sorry.)

    0 讨论(0)
提交回复
热议问题