Platforms to show: All Mac Windows Linux Cross-Platform
Required plugins for this example: MBS Tools Plugin
You find this example project in your Plugins Download as a Xojo project file within the examples folder: /Tools/Tidy/Tidy XML
This example is the version from Thu, 15th Feb 2023.
Project "Tidy XML.xojo_binary_project"
FileTypes
Filetype text
End FileTypes
Class WindowSimple Inherits Window
Control EditField1 Inherits TextArea
ControlInstance EditField1 Inherits TextArea
End Control
Control EditField2 Inherits TextArea
ControlInstance EditField2 Inherits TextArea
End Control
EventHandler Sub Open()
Dim t As TidyDocumentMBS
// the easiest way by just passing strings in and out
t=new TidyDocumentMBS
t.InstallErrorBuffer
const input="<test><firstName>Bob</firstName><lastName>Miller</test>"
t.OptionXmlTags = true
t.OptionXhtmlOut = false
t.OptionUpperCaseAttrs = false
t.OptionUpperCaseTags = false
t.OptionQuiet = true
t.OptionQuoteAmpersand = true
t.OptionQuoteMarks = true
// will show the message about lastName closing tag missing!
// -> that is correct for demonstration the capability
call t.ParseString(input)
call t.CleanAndRepair
call t.RunDiagnostics
t.OptionForceOutput=true
EditField1.text=t.SaveString
EditField2.Text=t.ErrorBuffer
End EventHandler
End Class
MenuBar MenuBar1
MenuItem UntitledMenu2 = ""
MenuItem FileMenu = "&File"
MenuItem FileQuit = "Quit"
MenuItem UntitledMenu5 = ""
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu0 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "Clear"
MenuItem UntitledMenu4 = ""
MenuItem UntitledMenu3 = ""
MenuItem UntitledMenu1 = ""
End MenuBar
Class App Inherits Application
End Class
Class MyOutput Inherits TidyOutputMBS
EventHandler Sub WriteByte(value as integer)
s=s+chrb(value)
// I know it is UTF8, so show a copy
e.text=DefineEncoding(s,Encodings.UTF8)
End EventHandler
Property e As TextArea
Property s As string
End Class
Class MyInput Inherits TidyInputMBS
EventHandler Function EndOfFile() As boolean
Return index=count
End EventHandler
EventHandler Function GetByte() As integer
// return one byte
index=index+1
Return ascb(midb(data,index,1))
End EventHandler
EventHandler Sub UngetByte(value as integer)
index=index-1
// we hope the value is the one from the string
End EventHandler
Sub Constructor(s as string)
data=s
count=lenb(s)
index=0
End Sub
Property Private count As integer
Property Private data As string
Property Private index As integer
End Class
Class MyTidyDocument Inherits TidyDocumentMBS
EventHandler Function Filter(level as integer, line as integer, column as integer, message as string) As boolean
MsgBox message
End EventHandler
End Class
End Project
See also:
The items on this page are in the following plugins: MBS Tools Plugin.