首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

急读取xml并比较,先多谢了

2012-01-13 
急,读取xml并比较,先谢谢了!我要读取一xml文档内的所有记录,看看记录内是否有文件名为pathname1的记录xml

急,读取xml并比较,先谢谢了!
我要读取一xml文档内的所有记录,看看记录内是否有文件名为pathname1的记录
xml格式为  
<?xml   version= "1.0 "   ?>  
-   <Team>
-   <Backup>
    <Filename> Event20070618100236001.avi </Filename>  
    <Time> 2006-2-8   11:12:31 </Time>  
    </Backup>
    </Team>
急啊   ,谢谢了

[解决办法]
' 一下代码未经过测试

Imports System.Xml

Public Class Form1

Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim x As New XmlDocument
x.Load( "a.xml ")
For Each el As XmlElement In x.GetElementsByTagName( "Backup ")
If el.GetElementsByTagName( "Filename ")(0).InnerText = "pathname1 " Then
MsgBox( "FOUND! ")
End If
Next
End Sub

End Class
[解决办法]
用XPath搜索吧!
[解决办法]
XmlDocument doc = new XmlDocument();
doc.Load(...);

string xpath = "/Backup[Filename= 'pathname1 '] ";

XmlNode node = doc.SelectSingleNode(xpath);

return node != null;
[解决办法]
如果是完全匹配

Imports System.Xml

Public Class Form1
Inherits System.Windows.Forms.Form

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xmlDoc As New XmlDocument
xmlDoc.Load( "C:\\XXX.xml ")
For Each x As XmlElement In xmlDoc.GetElementsByTagName( "Backup ")
If x.GetElementsByTagName( "Filename ")(0).InnerText = "pathname1 " Then
MsgBox( "Found ")
End If
Next
End Sub
End Class

热点排行