''' <summary> ''' XMLから値を取得 ''' </summary> ''' <param name="xmlPath">XMLファイルパス</param> ''' <param name="key">キー</param> ''' <returns>値</returns> ''' <remarks></remarks> Public Shared Function GetValueFromXML(ByVal key As String, ByVal xmlPath As String) As String Dim value As String = "" Dim xmlReader As XmlTextReader = Nothing Try xmlReader = New XmlTextReader(xmlPath) While xmlReader.Read If xmlReader.Name = "add" Then If xmlReader.AttributeCount > 0 Then While xmlReader.MoveToNextAttribute If xmlReader.Name = key Then value = xmlReader.Value Exit While End If If xmlReader.GetAttribute(0) = key Then value = xmlReader.GetAttribute(1) Exit While End If End While If value <> "" Then Exit While End If End If End If End While Return value Catch ex As Exception Throw ex Finally If Not xmlReader Is Nothing Then xmlReader.Close() End If End Try End Function 本例是从web.config中读取相关内容,如果是自己创建的xml,可能需要做相应的更改