1. 외부 XML 파일 읽기 [Bottom] [Top]
- Visual Basic 소스 코드
1 Imports System.Xml 2 3 Module Module1 4 5 Sub Main() 6 7 Dim svrInfo As SvrInfo() = ReadXmlFile("http://localhost/ServerInfo.xml") 8 Dim i As Integer 9 10 For i = 0 To svrInfo.Length - 1 11 Console.Write("ID : ") 12 Console.WriteLine(svrInfo(i).nSvrID) 13 Console.WriteLine("Name : " + svrInfo(i).strSvrName) 14 Console.WriteLine("DBConn : " + svrInfo(i).strDBConn) 15 Next 16 17 End Sub 18 19 Function ReadXmlFile(ByVal strXmlFile As String) As SvrInfo() 20 21 ' Web Service 일 경우 실제 경로 추가 22 ' Dim strXmlPath As String = Context.Request.PhysicalApplicationPath() + "\" + strXmlFile 23 ' Dim reader As XmlTextReader = New XmlTextReader(strXmlFile) 24 25 Dim reader As XmlTextReader = New XmlTextReader(strXmlFile) 26 Dim svrInfo As SvrInfo() 27 Dim nSvr As Integer = -1 28 29 reader.MoveToContent() 30 31 While (reader.Read()) 32 If reader.NodeType = XmlNodeType.Element Then 33 Select Case reader.Name 34 Case "SvrInfo" 35 nSvr = nSvr + 1 36 ReDim Preserve svrInfo(nSvr) 37 svrInfo(nSvr) = New SvrInfo 38 Case "SID" 39 reader.Read() 40 svrInfo(nSvr).nSvrID = reader.Value 41 Case "Name" 42 reader.Read() 43 svrInfo(nSvr).strSvrName = reader.Value 44 Case "DBConnString" 45 reader.Read() 46 svrInfo(nSvr).strDBConn = reader.Value 47 End Select 48 End If 49 End While 50 51 Return svrInfo 52 53 End Function 54 55 Class SvrInfo 56 Public nSvrID As Integer 57 Public strSvrName As String 58 Public strDBConn As String 59 End Class 60 61 End Module 62
예제 - ServerInfo.xml
<?xml version="1.0" encoding="UTF-8"?> <Server> <SvrInfo> <SID>1</SID> <Name>서버 1</Name> <DBConnString>Provider={MySQL};SERVER=localhost;DSN=DB_DSN_1;UID=User1;PWD=1234;DATABASE=db_1</DBConnString> </SvrInfo> <SvrInfo> <SID>2</SID> <Name>서버 2</Name> <DBConnString>Provider={MySQL};SERVER=localhost;DSN=DB_DSN_2;UID=User2;PWD=1234;DATABASE=db_2</DBConnString> </SvrInfo> </Server>
2. 세션 처리 [Bottom] [Top]
코드 정리 중...
3. ODBC 연결 & DB 쿼리 방법 [Bottom] [Top]
코드 정리 중...
4. Base64 Encode & Decode [Bottom] [Top]
코드 정리 중...
