感谢您使用微软产品。在Dim studentinfo1 = studentinfo.SelectSingleNode("//student[course='" + coursename + "']")这句中,您定义的XPath语句出现了错误,这句xpath的意思是在XML的所有节点中查找课程为coursename的第一个节点,这样,您将总是无法准确地定位,针对您的XML文件,解决这个问题可以有两个办法。1、用前一句获得的studentinfo节点的ChildNode属性,检查是否已经存在了Course子节点。例如:
Dim n As XmlNode
For Each n In student.ChildNodes
    If n.Name = "course" And n.InnerText = coursename Then
     MsgBox("你已经选修了课程")
    End If
Next2、通过xpath语句定位该节点,定位到student节点中sid=5的course节点的xpath语句为:“”即
Dim course As XmlNode = root.SelectSingleNode("//student[sid= '" + sid.Text + "']/course[.='" + coursename + "']")
If Not course Is Nothing Then
     MsgBox("你已经选修了课程")
End If关于Xpath您可以参考一下文章:
Introduction to the XPath Tree Model
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/xmlsdk/htm/xpath_concepts1_6jho.asp微软全球技术中心 VB技术支持
本贴子以“现状”提供且没有任何担保,同时也没有授予任何权利。具体事项可参见使用条款(http://support.microsoft.com/directory/worldwide/zh-cn/community/terms_chs.asp)。