Well i have troubles sorting the xml whenever i created a new info so here are the codes
Imports System.Xml
Imports System.IO
Imports System.Text
Public Class Form1
Dim m_strdata As String(,) = New String(999, 4) {}
Dim w As Integer = 0
Private Sub read()
Dim m_xmlr As XmlTextReader
'Create the XML Reader
If File.Exists("1.xml") Then
m_xmlr = New XmlTextReader("1.xml")
'Disable whitespace so that you don't have to read over whitespaces
m_xmlr.WhitespaceHandling = WhitespaceHandling.None
'read the xml declaration and advance to family tag
m_xmlr.Read()
'read the family tag
m_xmlr.Read()
'Load the Loop
While Not m_xmlr.EOF
'Go to the name tag
m_xmlr.Read()
'if not start element exit while loop
If Not m_xmlr.IsStartElement() Then
Exit While
End If
m_xmlr.Read()
'Get the firstName Element Value
'Get the lastName Element Value
m_strdata(w, 0) = m_xmlr.ReadElementString("Day")
w = w + 1
'Write Result to the Console
End While
'close the reader
m_xmlr.Close()
End If
End Sub
Private Sub write()
Dim Writer As XmlTextWriter = New XmlTextWriter("1.xml", Encoding.UTF8)
Dim Filename As String = "1.xml"
Dim DOMDocument As XmlDocument = New XmlDocument
Dim write As String
Dim converter As Integer
Dim number As Integer = 0
Dim trigger As Integer = 0
Dim RootElement As XmlElement
Dim Element As XmlElement
Dim TextVideo As XmlText
converter = Convert.ToInt64(TextBox1.Text)
If (converter < Convert.ToInt64(m_strdata(0, 0))) Then
write = converter.ToString
trigger = 1
Else
write = m_strdata(0, 0)
End If
Writer.WriteStartDocument()
Writer.WriteStartElement("Events")
Writer.WriteStartElement("students")
Writer.WriteElementString("Day", write)
Writer.WriteEndElement()
'add tags / elements
'add tags / elements
Writer.WriteEndElement()
Writer.WriteEndDocument()
'everything written here are kept override and replce
Writer.Flush()
Writer.Close()
While w <> 0 'total events is the same
w = w - 1
If (trigger = 0 AndAlso converter < Convert.ToInt64(m_strdata(number + 1, 0))) Then
write = converter.ToString
trigger = 1
DOMDocument.Load(Filename)
RootElement = DOMDocument.DocumentElement
Element = DOMDocument.CreateElement("students")
RootElement.AppendChild(Element)
RootElement = DOMDocument.DocumentElement
Element = DOMDocument.CreateElement("Day")
TextVideo = _
DOMDocument.CreateTextNode(write)
RootElement.LastChild.AppendChild(Element)
RootElement.LastChild.LastChild.AppendChild(TextVideo)
DOMDocument.Save(Filename)
number = number + 1
End If
DOMDocument.Load(Filename)
RootElement = DOMDocument.DocumentElement
Element = DOMDocument.CreateElement("students")
RootElement.AppendChild(Element)
RootElement = DOMDocument.DocumentElement
Element = DOMDocument.CreateElement("Day")
TextVideo = _
DOMDocument.CreateTextNode(m_strdata(number, 0))
RootElement.LastChild.AppendChild(Element)
RootElement.LastChild.LastChild.AppendChild(TextVideo)
DOMDocument.Save(Filename)
number = number + 1
End While
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim Filename As String = "1.xml"
Dim DOMDocument As XmlDocument = New XmlDocument
If File.Exists(Filename) Then
read()
My.Computer.FileSystem.DeleteFile("1.xml")
write()
'"Append" to next info the previous 1 need something....
Else
Dim Writer As XmlTextWriter = New XmlTextWriter("1.xml", Encoding.UTF8)
Writer.WriteStartDocument()
Writer.WriteStartElement("Events")
Writer.WriteStartElement("students")
Writer.WriteElementString("Day", TextBox1.Text)
Writer.WriteEndElement()
'add tags / elements
'add tags / elements
Writer.WriteEndElement()
Writer.WriteEndDocument()
'everything written here are kept override and replce
Writer.Flush()
Writer.Close()
End If
End Sub
End Class
The results if i create 4, 2, 3, 1 are
<?xml version="1.0" encoding="UTF-8"?>
-<Events>
-<students>
<Day>1</Day>
</students>
-<students>
<Day>2</Day>
</students>
-<students>
<Day>3</Day>
</students>
-<students>
<Day>4</Day>
</students>
-<students>
<Day> </Day>
</students>
</Events>
The results if i create 4, 2, 3, 5 are
<?xml version="1.0" encoding="UTF-8"?>
-<Events>
-<students>
<Day>2</Day>
</students>
-<students>
<Day>2</Day>
</students>
-<students>
<Day>3</Day>
</students>
-<students>
<Day>4</Day>
</students>
-<students>
<Day>4</Day>
</students>
</Events>
so any1 can help me please?