Dim Domxmldocument as system.xml.xmldocument Dim TmpPath As String = AppTempFilePath Dim XMLFile As String = TmpPath "/TestXML.XML"
'Form load event Private Sub TestXml_Load (ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load' read xml test procedure Dim tmpPath As String = AppTempFilePath Dim xmlFile As by Dim domXmlDocument As System.Xml.XmlDocument String = tmpPath "/testXml.xml" Dim reader As System.Xml.XmlReader = Nothing Try reader = New Xml.XmlTextReader (xmlFile) 'reader. While reader.Read Me.lboxXml.Items.Add (reader.Name reader .Value) End while
Catch exception msgbox (ex.Message) Finally if not (Reader is nothing) Then reader.close () end if End Try
End Sub
'Load XML Event Private sub btnxmlload_click (Byval e as system.EventArgs) handles btnxmlload.click' me.lboxxml.Items.clear () '' reading XML process test
'Dim Reader As System.xml.xmlreader = Nothing' Try 'Reader = New Xml.xmlTextReader (XMLFile)' While Reader.Read 'me.lboxxml.Items.add (Reader.Name ":" Reader.Value)' End while 'catch exception' msgbox (ex.Message) 'Finally' IF (Reader is nothing) Then 'Reader.close ()' end if 'End DIM DS AS NEW DATASET TRY' If you use DS directly to do DataSource The DataGrid will not be expanded, and it can be directly displayed correctly with DV. ds.ReadXml (xmlFile) Dim tb As DataTable Dim dv As DataView tb = ds.Tables (0) dv = New DataView (tb) DataGrid1.DataSource = dv 'DataGrid1.DataMember = "testXmlMember"' DataGrid1.DataMember = "employeefname" 'DIM DXD AS New XMLDATADOCUMENT CATCH EX AS Exception Msgbox (ex.Message.toString) End Tryend Sub
'Save New XML Content Event Private Sub BtnsAvenew_Click (Byval E AS System.EventArgs) Handles BtnsaVenew.click
DIM MyTW As New XMLTextWriter (TmpPath "/ TestXMLWRITE.XML", NOTING
Mytw.writestartDocument () mytw.formatting = formatting.indented
MyTW.WriteStartElement ("team")
myTW.WriteStartElement ( "player") myTW.WriteAttributeString ( "Name", "George Zip") myTW.WriteAttributeString ( "Position", "QB") myTW.WriteElementString ( "Nickname", "Zippy") myTW.WriteElementString ( " JerseyNumber, XMLConvert.toString (7))
MyTw.writeEndelement () myTw.writeEndelement ()
myTw.writeEndDocument ()
Mytw.close ()
End Sub
It will not be made for modifying the contents specified in the DataGrid and saved to XML, it understands, written in VB.NET and XML reading 2!