Platforms to show: All Mac Windows Linux Cross-Platform

/XML/XML


Required plugins for this example: MBS XML Plugin

You find this example project in your Plugins Download as a Xojo project file within the examples folder: /XML/XML

This example is the version from Mon, 28th Aug 2022.

Project "XML.xojo_binary_project"
Class App Inherits DesktopApplication
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class MainWindow Inherits DesktopWindow
Const SampleXML = "<?xml version=""1.0"" encoding=""UTF-8""?>\n<League>\n\t<Team name=""Seagulls"">\n\t\t<Player name=""Bob"" position=""1B"" />\n\t\t<Player name=""Tom"" position=""2B"" />\n\t</Team>\n\t<Team name=""Pigeons"">\n\t\t<Player name=""Bill"" position=""1B"" />\n\t\t<Player name=""Tim"" position=""2B"" />\n\t</Team>\n\t<Team name=""Crows"">\n\t\t<Player name=""Ben"" position=""1B"" />\n\t\t<Player name=""Ty"" position=""2B"" />\n\t</Team>\n</League>"
Control XMLList Inherits DesktopListBox
ControlInstance XMLList Inherits DesktopListBox
EventHandler Sub RowExpanded(row As Integer) If Me.RowTagAt(row) IsA XmlElementMBS Then LoadChildren(XmlElementMBS(XmlList.RowTagAt(row))) End If End EventHandler
End Control
Control SelectXMLButton Inherits DesktopButton
ControlInstance SelectXMLButton Inherits DesktopButton
EventHandler Sub Pressed() Var xmlFile As FolderItem xmlFile = FolderItem.ShowOpenFileDialog("") If xmlFile <> Nil And xmlFile.Exists Then LoadAndDisplay(xmlFile) End If End EventHandler
End Control
EventHandler Sub Opening() Var xml As New XmlDocumentMBS xml.LoadXml(SampleXML) LoadXml(xml) End EventHandler
Private Sub LoadAndDisplay(xmlFile As FolderItem) XmlList.RemoveAllRows Var xml As New XMLDocumentMBS Try xml.LoadXml(xmlFile) Catch e As XMLExceptionMBS MessageDialog.Show("This does not appear to be an XML file.") Return End Try LoadXml(xml) End Sub
Private Sub LoadChildren(node As XMLElementMBS) // Process the children of this node If node.ChildCount > 0 Then // better loop over elements! For Each child As XMLElementMBS In node.IterateElements // or by for loop with number 'Dim c As Integer = node.ChildElementCount 'For i As Integer = 0 To c-1 'Dim child As XMLElementMBS = node.Element(i) // Collect attributes to display Var attr As String If child.AttributeCount > 0 Then For a As Integer = 0 To child.AttributeCount - 1 Var an As XmlAttributeMBS an = child.AttributeNode(a) attr = attr + " " + an.Name + "=""" + an.Value + """" Next End If If child.ChildElementCount > 0 Then // This child is also a parent, so add it as a folder // and save the node so that it can be displayed // when it is expanded. XmlList.AddExpandableRow(child.Name + attr) XmlList.RowTagAt(XmlList.LastAddedRowIndex) = child Else // The node is either a comment or a text node // CDATASections are not processed XMLList.AddRow(child.Name + attr) // look into first text as content of the node Dim v As Variant = child.FirstChild If v IsA XMLTextMBS Then Dim t As XMLTextMBS = v XMLList.CellTextAt(XMLList.LastAddedRowIndex, 1) = t.WholeText End If End If Next End If End Sub
Private Sub LoadXml(xml As XmlDocumentMBS) // Create the folder for the root node XmlList.AddExpandableRow(xml.DocumentElement.Name) // Save the root node. It will be processed by LoadChildren // when the folder is expanded (XMLList.ExpandRow) XmlList.RowTagAt(XmlList.LastAddedRowIndex) = xml.DocumentElement End Sub
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem UntitledMenu1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem UntitledMenu0 = "-"
MenuItem EditSelectAll = "Select &All"
End MenuBar
End Project

See also:

The items on this page are in the following plugins: MBS XML Plugin.


The biggest plugin in space...