vb.net ways to create, modify, and read XML __.net

Source: Internet
Author: User
"' <summary>
"" Create an XML file
"' </summary>
' <param name= ' xmlfilename > XML filename to be created </param>
"' <remarks></remarks>
Private Sub Createxml () Sub Createxml (ByVal xmlfilename as String)
Try
Dim writer as New Xml.xmltextwriter (Application.startuppath & "" & XMLfileName, System.Text.Encoding.GetEncoding ("Utf-8"))
' Use automatic indentation for easy reading
Writer. formatting = Xml.Formatting.Indented
Writer. WriteRaw ("<?xml version=" "1.0" "encoding=" "Utf-8" "?>")
' Write the root element ()
Writer. WriteStartElement ("Config")
' Add subordinate elements
Writer. WriteStartElement ("databasesetting")
' Add child element ()
Writer. WriteElementString ("DataSource", Me.cmbHostName.SelectedItem.ToString.Trim)
' Add a property of value to DataSource and a property of test
' Writer. WriteAttributeString ("Value", "Test")
Writer. WriteElementString ("InitialCatalog", Me.cmbDatabaseName.SelectedItem.ToString.Trim)
Writer. WriteElementString ("UserID", Me.txtUserName.Text.Trim)
Writer. WriteElementString ("Password", Me.txtPassword.Text.Trim)
' Turn off the subordinate element databasesetting
Writer. WriteEndElement ()
' Add subordinate element stationsetting
Writer. WriteStartElement ("stationsetting")
' Add child elements
Writer. WriteElementString ("StoreID", Me.cmbStoreID.SelectedItem.ToString.Trim)
Writer. WriteElementString ("Stationid", Me.cmbStationID.SelectedItem.ToString.Trim)
' Turn off the subordinate element stationsetting
Writer. WriteEndElement ()
' Close the root element
Writer. Writefullendelement ()
' Write XML to file and close writer
Writer. Close ()
Catch ex as Exception
MsgBox (ex. Message & VbCrLf & ex. StackTrace)
End Try
End Sub
"' <summary>
"" Modify XML
"' </summary>
' <param name= ' xmlfilename > XML filename to be modified </param>
"<param name=" rootname >xml file root element name </param>
' <param name= ' elementnamearry > array of elements to be modified </param>
' <param name= ' innertextarry > Modified text array corresponding to the array of elements to be modified </param>
"' <remarks></remarks>
Public Sub modifxml () Sub Modifxml (ByVal xmlfilename As String, ByVal Rootname as String, ByVal Elementnamearry () as Str ING, ByVal innertextarry () as String)
If My.Computer.FileSystem.FileExists (Application.StartupPath.Trim & "" & XMLfileName) Then
Dim Doc as New xml.xmldocument
Doc. Load (Application.StartupPath.Trim & "" & XMLfileName)
Dim list as Xml.xmlnodelist = Doc. selectSingleNode (Rootname). ChildNodes
For each xn as xml.xmlnode in list
Dim XE as Xml.xmlelement
Xe = xn
Dim NLS as Xml.xmlnodelist = Xe. ChildNodes
For each

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.