PBToolboxAI v3 ← Site

xmltree — u_pbt_xmltree #

← Component reference · Guide contents

xmltree shows a XML value as a collapsible tree, colour-coded: a config screen, an API response, an integration debug. You set the XML text in is_xml, the component shows it; a click on a node reports its path (ue_node_clicked), invalid XML raises ue_error. It changes nothing: it is a VIEWER.

▶ See it live — Demo application, XML tree tile, with the code and this page side by side.


At a glance #

Userobjectu_pbt_xmltree
InputThe XML text, in is_xml (a string)
Fold / unfoldEach container by its chevron, or all at once (of_expand_all, of_collapse_all)
FeedbackA click on a node gives its path (ue_node_clicked); invalid XML raises ue_error

Quick start #

// Show an XML response as a tree
uo_xml.is_xml = inv_rest.of_response_text()

// Fold everything, then let the user open what interests them
uo_xml.of_collapse_all()

// ue_node_clicked : the path of the node clicked ("/order/lines/line[2]/@sku")
// -> an attribute node is .../@name

Properties #

PropertyTypeDefaultDescription
is_xmlstring""The XML text to show. An object, an array, a value; read and shown as a tree. Empty clears the tree; invalid XML raises ue_error and shows nothing
ib_wrapbooleantrueLong lines wrap (true, the default) or stay on one line with a horizontal scrollbar (false) — a code-editor feel
ib_search_enabledbooleantrueCtrl+F in the tree opens a search box — the same search as of_search: type to highlight, Enter next, Shift+Enter previous, Escape closes. false leaves the shortcut to an application that searches from its own box
is_theme_stylestringfluentVisual style of the component (THEME_STYLE_* constants)
is_theme_modestringlightLight or dark variant (THEME_MODE_* constants)
il_theme_accentlong-1Accent color of this component (-1 = the theme accent)
is_tooltipstring""Simple tooltip shown when hovering the component
is_super_tooltip_titlestring""Title of the rich tooltip (takes precedence over is_tooltip)
is_super_tooltip_textstring""Text of the rich tooltip (rich markup accepted)
is_super_tooltip_imagestring""Image of the rich tooltip

Methods #

MethodDescription
of_expand_all ( ) → longUnfolds every container. Returns 0, -1 when the component is not created
of_collapse_all ( ) → longFolds every nested container (the top level stays visible). Returns 0, -1 when the component is not created
of_clear ( ) → longEmpties the tree (like is_xml = ""). Returns 0, -1 when the component is not created
of_expand_to_level ( long al_level ) → longShows the tree down to al_level: elements at that depth or deeper fold shut (1 = the root's direct children, 0 folds the root)
of_search ( string as_query ) → longHighlights every occurrence (case-insensitive) and jumps to the first, opening any collapsed ancestor; ue_search_result says how many. An empty query clears the search. The search box opens with the query in it and the focus on it (the same box as Ctrl+F): Enter steps to the next match; with ib_search_enabled false the tree only highlights
of_search_next ( ) → longMoves to the NEXT match (wraps to the first after the last); ue_search_result reports the new position. Returns 0, or a negative code
of_search_prev ( ) → longMoves to the PREVIOUS match (wraps to the last before the first); ue_search_result reports the new position. Returns 0, or a negative code
of_clear_search ( ) → longDrops the search: no more highlights and no current match (of_match_count answers 0), and the search box empties and closes. Returns 0, or a negative code
of_select_path ( string as_path ) → longSelects and scrolls to the line at as_path WITHOUT raising an event (the app drove it)
of_selected_path ( ) → stringThe path of the selected line, read LIVE (/r/b/c, /r/a/@id) — what a Copy button copies. Empty when nothing is selected
of_selected_value ( ) → stringThe text of the selected line when it is a LEAF (an element's text, an attribute's value), read LIVE. Empty for a container element, or with no selection
of_match_count ( ) → longReturns how many matches the current search found, read LIVE — the 12 of a 3 / 12 status line. 0 with no search
of_match_index ( ) → longReturns the 1-based position of the current match, read LIVE — the 3 of a 3 / 12 status line. 0 with no match

Events #

EventWhen
ue_node_clicked (string as_path)The user clicked a node: its access path (/order/lines/line[2]/@sku), to read back in your data
ue_selection_changed (string as_path)The selected line changed by KEYBOARD (arrows, Home/End) — a mouse click reports ue_node_clicked
ue_search_result (long al_count, long al_index)A search ran or moved: al_count matches in all, the current one is al_index (1-based, 0 when none) — the makings of a "3 / 12" status line
ue_error (string as_message)The text in is_xml is not valid XML: the message says why, the tree stays empty

Example #

Explore an API response #

if inv_rest.of_get("https://api.example.com/orders/4152") = 200 then
	uo_xml.is_xml = inv_rest.of_response_text()
	uo_xml.of_collapse_all()          // the reader opens what interests them
else
	uo_xml.of_clear()
end if

Good practice #


Inherited from the common base #

These members exist on every visual component — they are not specific to this one. They are detailed once, in the transverse chapters; this table only says where to read them.

MembersRoleDetailed in
of_resetPut the component back to zero3.6 Resetting a component: of_reset()
of_register_shortcut · of_clear_shortcutsThe component's keyboard chords3.5 Keyboard shortcuts
of_is_created · of_is_ready · of_get_last_errorWhether it was born, whether it is ready, what failed3.7 Diagnostics
of_save_as_png · of_save_as_jpgExport the rendering as an image3.8 Exporting the rendering as an image
of_set_redrawGroup changes into a single repaint3.10 Best practices
of_preload_iconsIcons shown with no delayInstant display: of_icon
of_set_translationTranslate one of the component's labels5.2 Adapting a label: of_set_translation
of_focus_webviewGive the component the focus6.4 Keyboard and focus
of_print · of_print_to_pdfPrint, or write a PDF6.9 Printing
of_set_property · of_get_property · of_component_nameDriving a property by its name3.1 The property engine

← Component reference · Guide contents