Public Sub Readconnectionstring()
Dim xmldoc As New XmlDataDocument()
Dim xmlnode As XmlNodeList
Dim i As Integer
Dim str As String
Dim fs As New FileStream("XMLFile.xml", FileMode.Open, FileAccess.Read)
xmldoc.Load(fs)
xmlnode = xmldoc.GetElementsByTagName("constr")
For i = 0 To xmlnode.Count - 1
xmlnode(i).ChildNodes.Item(0).InnerText.Trim()
str = xmlnode(i).ChildNodes.Item(0).InnerText.Trim() & " | " & xmlnode(i).ChildNodes.Item(1).InnerText.Trim() & " | " & xmlnode(i).ChildNodes.Item(2).InnerText.Trim()
MsgBox(str)
Next
End Sub
because i don't know how to return value(connection string)
Public Function GetXmlConnection() As String
Dim connection As String = ""
Dim xml As New XmlDocument()
xml.Load(HttpContext.Current.Server.MapPath("~/App_Data/XmlReadSource.xml"))
Dim root As XmlNode = xml.SelectSingleNode("configuration")
Dim child As XmlNodeList = root.ChildNodes
For Each c As XmlNode In child
If TryCast(c, XmlElement).Name = "appsettings" Then
Dim xnl As XmlNodeList = c.ChildNodes
For Each xnf As XmlNode In xnl
Dim xe As XmlElement = DirectCast(xnf, XmlElement)
If xe.GetAttribute("key") = "constr" Then
connection = xe.GetAttribute("value")
Else
Continue For
End If
Next
Else
Continue For
End If
Next
Return connection
End Function
Member
55 Points
435 Posts
How to get connection string from xml file
Jun 05, 2013 04:47 AM|Mohammed Saleh|LINK
What is the code DOM or XPATH for get xml file connection string
please give me function code ,Thanks
Member
55 Points
435 Posts
Re: How to get connection string from xml file
Jun 05, 2013 05:58 AM|Mohammed Saleh|LINK
how to convert this sub method to function
because i don't know how to return value(connection string)
give this or code do this
Star
14544 Points
1481 Posts
Re: How to get connection string from xml file
Jun 07, 2013 03:22 AM|Amy Peng - MSFT|LINK
Hi,
For how to get connection string from the xml file, please try to refer to the following code:
Hope it can help you.
Best Regards,
Amy Peng
Member
55 Points
435 Posts
Re: How to get connection string from xml file
Jun 10, 2013 08:19 AM|Mohammed Saleh|LINK
this is correct answer :
Thank's guids