By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,952 Members | 1,616 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,952 IT Pros & Developers. It's quick & easy.

Connection string in XML File With DOM or xpath

P: 42
What is the code for DOM OR XPATH to connect xml file connection in my code(project)
How can I do this ,please help me ?
Jun 4 '13 #1

✓ answered by mohammed saleh

Expand|Select|Wrap|Line Numbers
  1. Public Function GetXmlConnection() As String
  2.     Dim connection As String = ""
  3.     Dim xml As New XmlDocument()
  4.     xml.Load(HttpContext.Current.Server.MapPath("~/App_Data/XmlReadSource.xml"))
  5.     Dim root As XmlNode = xml.SelectSingleNode("configuration")
  6.     Dim child As XmlNodeList = root.ChildNodes
  7.     For Each c As XmlNode In child
  8.         If TryCast(c, XmlElement).Name = "appsettings" Then
  9.             Dim xnl As XmlNodeList = c.ChildNodes
  10.             For Each xnf As XmlNode In xnl
  11.                 Dim xe As XmlElement = DirectCast(xnf, XmlElement)
  12.                 If xe.GetAttribute("key") = "constr" Then
  13.                     connection = xe.GetAttribute("value")
  14.                 Else
  15.                     Continue For
  16.                 End If
  17.  
  18.             Next
  19.         Else
  20.             Continue For
  21.         End If
  22.     Next
  23.     Return connection
  24. End Function

Share this Question
Share on Google+
7 Replies


Dormilich
Expert Mod 5K+
P: 8,639
depends on what language your code is in.
Jun 4 '13 #2

P: 42
@Dormilich
vb.net with asp (microsoft visual studio 2008)
I'm sorry for later

please help me
Jun 5 '13 #3

Dormilich
Expert Mod 5K+
P: 8,639
I do not know VB.NET so I cannot. Maybe the people in the .NET forum can.
Jun 5 '13 #4

P: 42
How can I get xml file(connectionstring) for my code

Please help me
Jun 6 '13 #5

Frinavale
Expert Mod 5K+
P: 9,731
The reason I haven't answered thus far is because I am unclear on what you are trying to do.

Since your question is vague, my answer is going to be vague as well.

If you want to load an XML file into your application for processing you should check out the XmlDocument Class.

You should probably also take a look at this MSDN article about How To: Load XML Data in the XML Web Server Control.

The MSDN Library is a great resource to use whenever you are developing in any .NET language.

-Frinny
Jun 6 '13 #6

P: 42
Expand|Select|Wrap|Line Numbers
  1. Public Function GetXmlConnection() As String
  2.     Dim connection As String = ""
  3.     Dim xml As New XmlDocument()
  4.     xml.Load(HttpContext.Current.Server.MapPath("~/App_Data/XmlReadSource.xml"))
  5.     Dim root As XmlNode = xml.SelectSingleNode("configuration")
  6.     Dim child As XmlNodeList = root.ChildNodes
  7.     For Each c As XmlNode In child
  8.         If TryCast(c, XmlElement).Name = "appsettings" Then
  9.             Dim xnl As XmlNodeList = c.ChildNodes
  10.             For Each xnf As XmlNode In xnl
  11.                 Dim xe As XmlElement = DirectCast(xnf, XmlElement)
  12.                 If xe.GetAttribute("key") = "constr" Then
  13.                     connection = xe.GetAttribute("value")
  14.                 Else
  15.                     Continue For
  16.                 End If
  17.  
  18.             Next
  19.         Else
  20.             Continue For
  21.         End If
  22.     Next
  23.     Return connection
  24. End Function
Jun 11 '13 #7

P: 42
Frinavale
How to do XML Serializable for this code XML DOM connection string
Jun 16 '13 #8

Post your reply

Sign in to post your reply or Sign up for a free account.