Click here to Skip to main content
15,911,786 members
Home / Discussions / Visual Basic
   

Visual Basic

 
GeneralRe: INI - read multiline! Pin
User 989707412-Dec-16 6:40
User 989707412-Dec-16 6:40 
GeneralRe: INI - read multiline! Pin
Eddy Vluggen12-Dec-16 7:44
professionalEddy Vluggen12-Dec-16 7:44 
GeneralRe: INI - read multiline! Pin
User 989707412-Dec-16 8:31
User 989707412-Dec-16 8:31 
GeneralRe: INI - read multiline! Pin
Eddy Vluggen12-Dec-16 8:44
professionalEddy Vluggen12-Dec-16 8:44 
GeneralRe: INI - read multiline! Pin
User 989707412-Dec-16 8:59
User 989707412-Dec-16 8:59 
GeneralRe: INI - read multiline! Pin
Eddy Vluggen12-Dec-16 11:37
professionalEddy Vluggen12-Dec-16 11:37 
GeneralRe: INI - read multiline! Pin
User 989707414-Dec-16 4:45
User 989707414-Dec-16 4:45 
GeneralRe: INI - read multiline! Pin
Eddy Vluggen14-Dec-16 6:17
professionalEddy Vluggen14-Dec-16 6:17 
Alienoiz wrote:
The only problem is that is writing and reading only the first node.
I only see one call to the "createNode" method. What happens if you call that method twice?
XML
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<MEMOSAVE>
  <15/12/2016>  
    <Date>15/12/2016</Date>
    <Hour>01 : 05 PM</Hour>
    <Place>USA</Place>
    <Header>Testing Memo</Header>
    <MEMO>Memorando test text!</MEMO>
  </15/12/2016>
</MEMOSAVE>
Your fragment has an element with the name 15/12/2016, but element-names (the things between the < and >) aren't allowed to have slashes in them. You could name it "entry" though. You already have the date in the properties following that, so it would also be a bit redundant to specify it twice.

Alienoiz wrote:
i believe i can do it with a few lines of code and is nothing really hard..but yes..
You may need a bit more to handle multiple memo's.

I'd recommend creating a POCO, put those entries in a list, and XmlSerialize that. It looks more readable, and is easier to play with.
VB
Imports System.IO
Imports System.Xml.Serialization

' defines how our stuff looks
Public Class MyMemoEntry
    Public CreatedOn As DateTime ' contains both date and time
    Public Location As String
    Public Header As String
    Public Memo As String
End Class

Public Class Form1

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        ' create a list to hold our stuff
        Dim Entries As New List(Of MyMemoEntry)

        ' create new stuff
        Dim newEntry As New MyMemoEntry
        newEntry.CreatedOn = DateTime.Now
        newEntry.Location = "Home, sweet home"
        newEntry.Header = "How to build a decent chicken-soup"
        newEntry.Memo = "Call Mom and say you want chicken-soup"

        ' add new stuff to list
        Entries.Add(newEntry)

        ' save list to XML; for that we need a serializer
        Dim serializer As New XmlSerializer(Entries.GetType(), "space")

        ' write it to a filestream using said serializer
        Using FileStream As New FileStream("output.xml", FileMode.Create)
            serializer.Serialize(FileStream, Entries)
        End Using

    End Sub

End Class
Which results in a file similar to below;
XML
<?xml version="1.0"?>
<ArrayOfMyMemoEntry xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="space">
  <MyMemoEntry>
    <CreatedOn>2016-12-14T17:59:55.9937761+01:00</CreatedOn>
    <Location>Home, sweet home</Location>
    <Header>How to build a decent chicken-soup</Header>
    <Memo>Call Mom and say you want chicken-soup</Memo>
  </MyMemoEntry>
</ArrayOfMyMemoEntry>
That should be somewhat easier than writing the XML using a writer directly.

Also note that above saves a list of entries, not just one entry. You can fetch the CreatedOn property and get either the Date-part, the Time-part or both parts. Aw, and you don't have to use the "xml" file-extension when writing to a file, as long as you're using the right format.

Another nice thing about the above is that it is quite easy to replace the XmlSerializer with a JsonSerializer or the BinarySerializer. That way you are not limited or bound to XML.
Bastard Programmer from Hell Suspicious | :suss:
If you can't read my code, try converting it here[^]

GeneralRe: INI - read multiline! Pin
User 989707414-Dec-16 6:29
User 989707414-Dec-16 6:29 
GeneralRe: INI - read multiline! Pin
User 989707414-Dec-16 6:43
User 989707414-Dec-16 6:43 
GeneralRe: INI - read multiline! Pin
Eddy Vluggen14-Dec-16 7:08
professionalEddy Vluggen14-Dec-16 7:08 
GeneralRe: INI - read multiline! Pin
User 989707414-Dec-16 7:29
User 989707414-Dec-16 7:29 
GeneralRe: INI - read multiline! Pin
Eddy Vluggen14-Dec-16 10:46
professionalEddy Vluggen14-Dec-16 10:46 
GeneralRe: INI - read multiline! Pin
User 989707415-Dec-16 0:36
User 989707415-Dec-16 0:36 
GeneralRe: INI - read multiline! Pin
User 989707415-Dec-16 0:38
User 989707415-Dec-16 0:38 
GeneralRe: INI - read multiline! Pin
Richard MacCutchan15-Dec-16 1:42
mveRichard MacCutchan15-Dec-16 1:42 
GeneralRe: INI - read multiline! Pin
User 989707415-Dec-16 4:37
User 989707415-Dec-16 4:37 
GeneralRe: INI - read multiline! Pin
Eddy Vluggen15-Dec-16 5:00
professionalEddy Vluggen15-Dec-16 5:00 
GeneralRe: INI - read multiline! Pin
User 989707415-Dec-16 5:09
User 989707415-Dec-16 5:09 
GeneralRe: INI - read multiline! Pin
Eddy Vluggen15-Dec-16 8:35
professionalEddy Vluggen15-Dec-16 8:35 
GeneralRe: INI - read multiline! Pin
User 989707417-Dec-16 1:27
User 989707417-Dec-16 1:27 
GeneralRe: INI - read multiline! Pin
Eddy Vluggen17-Dec-16 23:46
professionalEddy Vluggen17-Dec-16 23:46 
GeneralRe: INI - read multiline! Pin
User 989707418-Dec-16 0:14
User 989707418-Dec-16 0:14 
GeneralRe: INI - read multiline! Pin
Eddy Vluggen18-Dec-16 1:16
professionalEddy Vluggen18-Dec-16 1:16 
GeneralRe: INI - read multiline! Pin
User 989707418-Dec-16 7:41
User 989707418-Dec-16 7:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.