#眉標=Mobile、XML、.NET CF #副標=Windows Mobile開發系列(15) #大標=行動裝置的資料存取(上) #作者=文/圖 沈炳宏 ============= 程式1 Dim xlr As New XmlTextWriter (fileName, System.Text.Encoding.Default) ds.WriteXml(xlr, XmlWriteMode.DiffGram) xlr.Close() ================ ============= 程式2 ================ ============= 程式3 Public Sub LoadXmlReader (ByVal fileName As String) Dim xlr As XmlTextReader  Try xlr = New XmlTextReader(fileName) Do While xlr.Read()   Select Case xlr.Name Case "runpc"    If xlr.IsStartElement Then …    End If Case "hadoop"    If xlr.IsStartElement Then … End If Case "Cloud" If xlr.IsStartElement Then … End If End Select Loop Catch e As XmlException Finally  xlr.Close() End Try End Sub ================ ============= 程式4 Public Sub WriteXml(ByVal fileName As String)  Dim fs As FileStream  Dim tw As XmlTextWriter Try   tw = New XmlTextWriter(fileName)   tw.WriteStartElement("runpc") … Catch e As XmlException Finally   tw.Close() End Try End Sub ================ ============= 程式5 Public Sub SaveToExternal( ByVal fileName As String)  Dim fs As FileStream  Dim sr As StreamWriter  Try fs = New FileStream( fileName, FileMode.Create, _   FileAccess.Write, FileShare.None) sr = New StreamWriter( fs, System.Text.Encoding.Default, 1024) …  Catch e As Exception Finally   sr.Close()  End Try End Sub ================ ============= 程式6 Public Sub LoadFromFile (ByVal fileName As String)  Dim fs As FileStream  Dim sr As StreamReader  Try fs = New FileStream(fileName, FileMode.Open, _ FileAccess.Read, FileShare.Read)   sr = New StreamReader(fs, True)   sr.ReadLine() Catch e As Exception Finally   sr.Close() End Try End Sub ================