Results 1 to 2 of 2

Thread: xml

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Nov 2003
    Posts
    1,489

    xml

    i am trying to externalize a connection string using xml.

    here is my xml:
    Code:
    <?xml version='1.0'?>
    <Settings>
      <Connection>
    	<UserID>sa</UserID>
    	<DataSource>Server</DataSource>
    	<InitialCatalog>Database</InitialCatalog>
      </Connection>
    </Settings>
    here is some code i'm trying to get the date with:
    VB Code:
    1. Imports System.Xml
    2. Module Module1
    3.  
    4.     Sub Main()
    5.         Dim reader As XmlTextReader = New XmlTextReader("Settings.xml")
    6.         While reader.Read()
    7.             If reader.NodeType = XmlNodeType.Text Then
    8.                 Console.WriteLine(reader.Value)
    9.             End If
    10.         End While
    11.  
    12.         Console.ReadLine()
    13.     End Sub
    14. End Module

    how can i build the connection string using 'UserID', 'DataSource', and 'InitialCatalog'?

    connectionObject.ConnectionString = (xml files userid, datasource, initial catalog)

    i'm lost

  2. #2
    Junior Member
    Join Date
    Sep 2004
    Location
    The BIG City
    Posts
    27
    Hi, try this

    Code:
        Dim m_xmld As XmlDocument
        Dim m_nodelist As XmlNodeList
        Dim m_node As XmlNode
        
        m_xmld = New XmlDocument()
    
        m_xmld.Load("Settings.xml")
    
        m_nodelist = m_xmld.SelectNodes("/Settings/Connection")
        
        For Each m_node In m_nodelist
           Dim UserID = m_node.ChildNodes.Item(0).InnerText
           Dim DataSource = m_node.ChildNodes.Item(1).InnerText
           Dim InitialCatalog = m_node.ChildNodes.Item(2).InnerText
        Next

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width