16,554
社区成员
发帖
与我相关
我的任务
分享
Dim dbSet As New DataSet
dbSet.ReadXml("C:\Pracice\XMLParseLearning\Sample.xml")
'Me.DataGrid1.DataSource = dbSet.Tables("COL")
MsgBox(dbSet.Tables("COL").Select("name = 'LXR'")(0).Item("Col_text").ToString)
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim DBSET As String = GetDBSET()
Dim s As String = GetValue("LXR", 1)
End Sub
Private Function GetDBSET() As String
Dim xmlDoc As New XmlDocument()
xmlDoc.Load("XML文件路径")
Dim mNode As XmlNode = xmlDoc.SelectSingleNode("DBSET")
Return mNode.Attributes("RESULT").InnerText.Trim()
End Function
Private Function GetValue(ByVal name As String, ByVal n As Integer) As String
Dim xmlDoc As New XmlDocument()
xmlDoc.Load("XML文件路径")
Dim mNodeList As XmlNodeList = xmlDoc.SelectNodes("DBSET/ROW/COL[@NAME='" & name & "']")
Return mNodeList(n).InnerText.Trim()
End Function
private void button1_Click(object sender, System.EventArgs e)
{
string DBSET = GetDBSET();//获取DBSET节点中RESULT属性的值“2”的方法
//获取“胡2”值的方法,由于XML数据结构是表结构,所以必须还需要类似行索引才能确定具体的值
string s = GetValue("LXR", 1);
}
private string GetDBSET()
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Application.StartupPath + "\\123.xml");
XmlNode mNode = xmlDoc.SelectSingleNode("DBSET");
return mNode.Attributes["RESULT"].InnerText.Trim();
}
//这里的两个参数分别是节点值和行索引
private string GetValue(string name, int n)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load(Application.StartupPath + "\\123.xml");
XmlNodeList mNodeList = xmlDoc.SelectNodes("DBSET/ROW/COL[@NAME='"+name+"']");
return mNodeList[n].InnerText.Trim();
}
Private Sub button1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim s As String = GetApplicationSetting("LXR")
End Sub
Private Function GetApplicationSetting(ByVal name As String) As String
Dim xmlDoc As New XmlDocument()
xmlDoc.Load("xm文件的路径")
Dim mNode As XmlNode = xmlDoc.SelectSingleNode("DBSET/ROW/COL[@NAME='" & name & "']")
Return mNode.InnerText.Trim()
End Function
private void button1_Click(object sender, System.EventArgs e)
{
string s = GetApplicationSetting("LXR");//这里就是你要获取的“胡”这个值
}
private string GetApplicationSetting(string name)
{
XmlDocument xmlDoc = new XmlDocument();
xmlDoc.Load("xm文件的路径");
XmlNode mNode = xmlDoc.SelectSingleNode("DBSET/ROW/COL[@NAME='"+name+"']");
return mNode.InnerText.Trim();
}