我想从其他站点获取数据并存储。尝试将字符串加载到XmlDocument时,提示我ArgumentException未被用户代码处理:路径中的字符非法。
这是下面的代码。
request.Method = WebRequestMethods.Http.Get
response = request.GetResponse()
If response.StatusCode = 200 Then
Dim reader As System.IO.Stream = response.GetResponseStream()
Dim readStream As New System.IO.StreamReader(reader, Encoding.UTF8)
Dim responseFromServer As String = readStream.ReadToEnd()
Dim xmld As XmlDocument
Dim nodelist As XmlNodeList
xmld = New XmlDocument()
xmld.Load(responseFromServer) //Error throws here
nodelist = xmld.GetElementsByTagName("a:data")
For Each node As XmlElement In nodelist
If node("a:id").InnerText.Trim = "name" Then 'Next Business Day response (NBD)- General Warranty
MsgBox(node("a:name").InnerText.Trim)
End If
Next
MsgBox(readStream)
End If
我尝试过的一种方法:
Dim readStream As New System.IO.StreamReader(reader, Encoding.UTF8)
Dim xmld As XmlDocument
Dim nodelist As XmlNodeList
xmld = New XmlDocument()
xmld.Load(readStream) //Error throws here
对于此方法,它返回为: XmlException未通过用户代码处理 根级别的数据无效。第1行,位置1。
然后尝试了不同的解决方案,但没有什么可以帮助我。我也尝试了loadxml 。
谢谢。
答案 0 :(得分:0)
尝试:
xmld.LoadXml(responseFromServer)
.Load
方法需要一个文件名。