Imports System.Collections.Generic
Imports System.Collections
Imports System.Collections.ObjectModel
Imports System.Reflection
Imports System.Xml.Serialization
Imports System.Xml.Schema
<XmlRoot("StationSetpoints")>
Public Partial Class XmlStationSetpoints
Public Property Setpoints As List(Of XmlStationSetpointsSetpoint)
Public Partial Class XmlStationSetpoints
<XmlAttribute("schemaLocation", Namespace:="http://www.w3.org/2001/XMLSchema-instance")>
Public Property xsiSchemaLocation() As String
Return "http://www.w3schools.com StationSetpoints.xsd"
Public Property xsiSchemaLocationSpecified() As Boolean
Public Class XmlStationSetpointsSetpoint
Public Property Points As List(Of XmlStationSetpointsSetpointPoint)
Public Class XmlStationSetpointsSetpointPoint
Public Property Order As String
Public Property InstrumentName As String
Public Property Value As String
Dim xml as String = GetXml()
Dim model = xml.LoadFromXml(Of XmlStationSetpoints)()
Dim newXml = model.GetXml()
Console.WriteLine(newXml)
model.xsiSchemaLocationSpecified = False
Dim newXml2 = model.GetXml()
Console.WriteLine(newXml2)
Function GetXml() As String
Dim xml as String = <StationSetpoints
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xsi:schemaLocation="http://www.w3schools.com StationSetpoints.xsd">
<Setpoint PartNumber="108022">
<Point InstrumentName="PD Stage" Value="10"/>
<Setpoint PartNumber="107983">
<Point Order="2" InstrumentName="PD Stage" Value="7.5"/>
</StationSetpoints>.ToString()
Public Module XmlSerializationHelper
<System.Runtime.CompilerServices.Extension> _
Public Function LoadFromXML(Of T)(xmlString As String) As T
Using reader As New StringReader(xmlString)
Return DirectCast(New XmlSerializer(GetType(T)).Deserialize(reader), T)
<System.Runtime.CompilerServices.Extension> _
Public Function GetXml(Of T)(obj As T, Optional omitStandardNamespaces As Boolean = False) As String
Dim ns As XmlSerializerNamespaces = Nothing
If omitStandardNamespaces Then
ns = New XmlSerializerNamespaces()
<System.Runtime.CompilerServices.Extension> _
Public Function GetXml(Of T)(obj As T, ns as XmlSerializerNamespaces) As String
Using textWriter = New StringWriter()
Dim settings = New XmlWriterSettings() With { _
Using xmlWriter = System.Xml.XmlWriter.Create(textWriter, settings)
Dim serializer as New XmlSerializer(obj.GetType())
serializer.Serialize(xmlWriter, obj, ns)
Return textWriter.ToString()
<System.Runtime.CompilerServices.Extension> _
Public Function GetOuterXml(node as XmlNode, Optional indent as Boolean = true) as String
Using textWriter = New StringWriter()
Dim settings = New XmlWriterSettings() With { _
.OmitXmlDeclaration = true _
Using xmlWriter = System.Xml.XmlWriter.Create(textWriter, settings)
Return textWriter.ToString()