我试图解析这个XML:
<?xml version="1.0" encoding="utf-8" ?>
<products xmlns="http://www.fusepumpaffiliates.co.uk/feed-distribution/etsy/us/">
<product>
<title>Product 1</title>
</product>
<product>
<title>Product 2</title>
</product>
<product>
<title>Product 3</title>
</product>
</products>
下面的代码与其他XML文件一起使用没有任何问题,因此我无法理解为什么下面的代码无法在此特定XML Feed上运行。 我甚至无法计算节点数量:
Dim req As HttpWebRequest
Dim Resp As HttpWebResponse
Dim reader As StreamReader
Dim responseString As String = ""
'get the XML
Dim productXML As New XmlDocument
Dim node As XmlNode
Dim root As XmlNode
req = HttpWebRequest.Create(fpm.feedURL)
req.Timeout = 3600000 '3600 seconds
Resp = req.GetResponse()
reader = New StreamReader(Resp.GetResponseStream)
responseString = reader.ReadToEnd()
productXML.LoadXml(responseString)
Dim mgr As XmlNamespaceManager = New XmlNamespaceManager(productXML.NameTable)
mgr.AddNamespace("whatever", productXML.DocumentElement.NamespaceURI)
root = productXML.DocumentElement
nodeList = root.SelectNodes("/products/product")
'nodeList.count = 0 here?!??!
For Each node In nodeList
If node.SelectSingleNode("categories") IsNot Nothing Then
End If
Next node
答案 0 :(得分:0)
显然,当XML中没有定义名称空间时,我可以使用名称空间的任何名称。但如果有一个名称空间,就像在我的feed中一样,我必须使用该名称空间。 现在它有效。