help in editing xml in VB
Okay so I'm trying to learn how to edit .xml whiten visual studio. I've gotten basic knowledge knowledge on .xml, however I don't know how to edit it. Here is an example .xml code that I want to edit. It's basic but a start.
HTML Code:
<?xml version="1.0" encoding="UTF-8"?>
<!-- Edited by XMLSpy -->
<note>
<to>Tove</to>
<from>Jani</from>
<heading>Reminder</heading>
<body>Don't forget me this weekend!</body>
</note>
Re: help in editing xml in VB
The way that I prefer to handle XML files, especially styled like how you have it, is to create a class and serialize it. Take a look at this class:
Code:
Public Class Note
Public Property [To] As String
Public Property From As String
Public Property Heading As String
Public Property Body As String
Sub New()
Me.To = String.Empty
Me.From = String.Empty
Me.Heading = String.Empty
Me.Body = String.Empty
End Sub
End Class
You could serialize and deserialize it like this:
Code:
Private Sub SerializeNote(ByVal path As String, ByVal note As Note)
Using sw As IO.StreamWriter = New IO.StreamWriter(path)
Dim x As Xml.Serialization.XmlSerializer = New Xml.Serialization.XmlSerializer(note.GetType)
x.Serialize(sw, note)
End Using
End Sub
Private Function DeserializeNote(ByVal path As String) As Note
Dim newNote As Note = New Note
Using sr As IO.StreamReader = New IO.StreamReader(path)
Dim x As Xml.Serialization.XmlSerializer = New Xml.Serialization.XmlSerializer(newNote.GetType)
newNote = DirectCast(x.Deserialize(sr), Note)
End Using
Return newNote
End Function
Re: help in editing xml in VB
what if there is a something like this:
<root>
<graphicsPreferences>
<entry>
<label> RENDER_PIPELINE </label>
<activeOption> 1 </activeOption>
</entry>
</graphicsPreferences>
</root>
If i need to edit the active option,
would it be the same or would you have to edit thx.