Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Written By: Iasanator
- Feel Free to Use For Whatever, Enjoy!
- Imports System
- Imports System.IO
- Imports System.Text
- Public Class XMLWriter_
- Dim fileStream As FileStream
- Dim level As New Dictionary(Of Integer, String)
- Dim path As String
- Dim IsNewLine As Boolean = True
- Public Sub CreateFile(ByVal p As String)
- path = p
- fileStream = File.Create(path)
- fileStream.Dispose()
- Dim extension As String
- extension = IO.Path.GetExtension(path).Replace(".", "")
- If extension = "html" Then
- My.Computer.FileSystem.WriteAllText(path, "<!DOCTYPE html>" & vbCrLf, False)
- ElseIf extension = "xml" Then
- My.Computer.FileSystem.WriteAllText(path, "<?xml version=" & ControlChars.Quote & "1.0" & ControlChars.Quote & " encoding=" & ControlChars.Quote & "utf-8" & ControlChars.Quote & "?>" & vbCrLf, False)
- Else
- My.Computer.FileSystem.WriteAllText(path, "<UNKNOWN FILE TYPE; ENTER HEADER HERE>" & vbCrLf, False)
- End If
- level.Add(0, "base")
- End Sub
- Public Overloads Sub WriteHeader(ByVal name As String, ByVal newLine As Boolean)
- TabOver()
- My.Computer.FileSystem.WriteAllText(path, "<" & name & ">", True)
- level.Add(GetHighestIndex() + 1, name)
- If newLine Then
- AddLine()
- Else
- IsNewLine = False
- End If
- End Sub
- Public Overloads Sub WriteHeader(ByVal name As String, ByVal var1 As String, ByVal val1 As String, ByVal newLine As Boolean)
- TabOver()
- My.Computer.FileSystem.WriteAllText(path, "<" & name & " " & var1 & "=" & ControlChars.Quote & val1 & ControlChars.Quote & ">", True)
- level.Add(GetHighestIndex() + 1, name)
- If newLine Then
- AddLine()
- Else
- IsNewLine = False
- End If
- End Sub
- Public Overloads Sub WriteHeader(ByVal name As String, ByVal parameters As Dictionary(Of String, String), ByVal newLine As Boolean)
- TabOver()
- My.Computer.FileSystem.WriteAllText(path, "<" & name, True)
- Dim temp As String = ""
- For Each n In parameters.Keys
- parameters.TryGetValue(n, temp)
- My.Computer.FileSystem.WriteAllText(path, " " & n & "=" & ControlChars.Quote & temp & ControlChars.Quote, True)
- Next
- My.Computer.FileSystem.WriteAllText(path, ">", True)
- level.Add(GetHighestIndex() + 1, name)
- If newLine Then
- AddLine()
- Else
- IsNewLine = False
- End If
- End Sub
- Public Sub WriteFooter()
- Dim holder As String = ""
- Dim i As Integer = 0
- If IsNewLine = True Then
- While i < GetHighestIndex() - 1
- My.Computer.FileSystem.WriteAllText(path, " ", True)
- i += 1
- End While
- End If
- level.TryGetValue(GetHighestIndex(), holder)
- My.Computer.FileSystem.WriteAllText(path, "</" & holder & ">", True)
- level.Remove(GetHighestIndex())
- AddLine()
- End Sub
- Public Sub WriteObject(ByVal name As String, ByVal parameters As Dictionary(Of String, String), ByVal newLine As Boolean, ByVal img As Boolean)
- TabOver()
- My.Computer.FileSystem.WriteAllText(path, "<" & name, True)
- Dim temp As String = ""
- For Each n In parameters.Keys
- parameters.TryGetValue(n, temp)
- My.Computer.FileSystem.WriteAllText(path, " " & n & "=" & ControlChars.Quote & temp & ControlChars.Quote, True)
- Next
- If img = True Then
- My.Computer.FileSystem.WriteAllText(path, ">", True)
- Else
- My.Computer.FileSystem.WriteAllText(path, "/>", True)
- End If
- If IsNewLine = True Then
- AddLine()
- End If
- End Sub
- Public Sub WriteText(ByVal text As String)
- TabOver()
- My.Computer.FileSystem.WriteAllText(path, text, True)
- If IsNewLine = True Then
- AddLine()
- End If
- End Sub
- Public Sub EndFile()
- For Each n In level.Keys
- If n > 0 Then
- WriteFooter()
- End If
- Next
- End Sub
- Private Sub AddLine()
- My.Computer.FileSystem.WriteAllText(path, vbCrLf, True)
- IsNewLine = True
- End Sub
- Private Sub TabOver()
- Dim i As Integer = 0
- If IsNewLine = True Then
- While i < GetHighestIndex()
- My.Computer.FileSystem.WriteAllText(path, " ", True)
- i += 1
- End While
- End If
- End Sub
- Private Function GetHighestIndex() As Integer
- Dim i As Integer = 0
- For Each n In level.Keys
- If i < n Then
- i = n
- End If
- Next
- Return i
- End Function
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement