Platforms to show: All Mac Windows Linux Cross-Platform

/XML/XML Path Query


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

This example is the version from Mon, 10th Sep 2023.

Project "XML Path Query.xojo_binary_project"
Class App Inherits DesktopApplication
Const kEditClear = "&Delete"
Const kFileQuit = "&Quit"
Const kFileQuitShortcut = ""
End Class
Class Window1 Inherits DesktopWindow
Const xmlString = "<?xml version=""1.0"" encoding=""UTF-8""?>\n<breakfast_menu>\n <food>\n <name>Belgian Waffles</name>\n <price>$5.95</price>\n <description>Two of our famous Belgian Waffles with plenty of real maple syrup</description>\n <calories>650</calories>\n </food>\n <food>\n <name>Strawberry Belgian Waffles</name>\n <price>$7.95</price>\n <description>Light Belgian waffles covered with strawberries and whipped cream</description>\n <calories>900</calories>\n </food>\n <food>\n <name>Berry-Berry Belgian Waffles</name>\n <price>$8.95</price>\n <description>Light Belgian waffles covered with an assortment of fresh berries and whipped cream</description>\n <calories>900</calories>\n </food>\n <food>\n <name>French Toast</name>\n <price>$4.50</price>\n <description>Thick slices made from our homemade sourdough bread</description>\n <calories>600</calories>\n </food>\n <food>\n <name>Homestyle Breakfast</name>\n <price>$6.95</price>\n <description>Two eggs, bacon or sausage, toast, and our ever-popular hash browns</description>\n <calories>950</calories>\n </food>\n</breakfast_menu>\n"
EventHandler Sub Opening() Var xml As New XMLDocumentMBS Try xml.LoadXml(xmlString) Catch e As XMLExceptionMBS MessageDialog.Show("This does not appear to be an XML file.") Return End Try // now let us run a query Dim root As XMLNodeMBS = xml.DocumentElement Dim result As XMLXPathResultMBS = xml.evaluate("/breakfast_menu/food/name", root, XMLXPathResultMBS.ResultTypeOrderedNodeSnapshot) Dim names() As String Dim length As Integer = result.SnapshotLength For i As Integer = 0 To length-1 if result.snapshotItem(i) then Dim node As XMLNodeMBS = result.NodeValue names.add node.toString End If Next MessageBox Join(names, EndOfLine) End EventHandler
End Class
MenuBar MainMenuBar
MenuItem FileMenu = "&File"
MenuItem FileQuit = "#App.kFileQuit"
MenuItem EditMenu = "&Edit"
MenuItem EditUndo = "&Undo"
MenuItem EditSeparator1 = "-"
MenuItem EditCut = "Cu&t"
MenuItem EditCopy = "&Copy"
MenuItem EditPaste = "&Paste"
MenuItem EditClear = "#App.kEditClear"
MenuItem EditSeparator2 = "-"
MenuItem EditSelectAll = "Select &All"
MenuItem HelpMenu = "&Help"
End MenuBar
End Project

See also:

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


The biggest plugin in space...