Xpath问题,为什么总得不到值,谢谢
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim myxmldocument As New XmlDocument
myxmldocument.Load(Server.MapPath( "XMLFile1.xml "))
Dim aa As XmlNodeList
Dim MyXpath As String
MyXpath = "//author "
Dim i As Integer
i = myxmldocument.DocumentElement.SelectNodes(MyXpath).Count
Response.Write(i)
End Sub
------解决方案--------------------如果取的点有名称空间要使用带名称空间的那个重载来取,否则取不到.
------解决方案--------------------up
------解决方案--------------------如果节点带名称空间...
请用上以下语句:
XmlNamespaceManager xnm = new XmlNamespaceManager(xmlDoc.NameTable);
xnm.AddNamespace( "pre ", "http://xxx.com/xxx.xxx ");//自己起的前缀和相应的url
xpath中这样用:MyXpath = "//pre:author "
------解决方案--------------------用XmlNamespaceManager这个来取