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 raisesue_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 #
| Userobject | u_pbt_xmltree |
| Input | The XML text, in is_xml (a string) |
| Fold / unfold | Each container by its chevron, or all at once (of_expand_all, of_collapse_all) |
| Feedback | A 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 #
| Property | Type | Default | Description |
|---|---|---|---|
is_xml | string | "" | 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_wrap | boolean | true | Long lines wrap (true, the default) or stay on one line with a horizontal scrollbar (false) — a code-editor feel |
ib_search_enabled | boolean | true | Ctrl+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_style | string | fluent | Visual style of the component (THEME_STYLE_* constants) |
is_theme_mode | string | light | Light or dark variant (THEME_MODE_* constants) |
il_theme_accent | long | -1 | Accent color of this component (-1 = the theme accent) |
is_tooltip | string | "" | Simple tooltip shown when hovering the component |
is_super_tooltip_title | string | "" | Title of the rich tooltip (takes precedence over is_tooltip) |
is_super_tooltip_text | string | "" | Text of the rich tooltip (rich markup accepted) |
is_super_tooltip_image | string | "" | Image of the rich tooltip |
Methods #
| Method | Description |
|---|---|
of_expand_all ( ) → long | Unfolds every container. Returns 0, -1 when the component is not created |
of_collapse_all ( ) → long | Folds every nested container (the top level stays visible). Returns 0, -1 when the component is not created |
of_clear ( ) → long | Empties the tree (like is_xml = ""). Returns 0, -1 when the component is not created |
of_expand_to_level ( long al_level ) → long | Shows 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 ) → long | Highlights 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 ( ) → long | Moves 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 ( ) → long | Moves 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 ( ) → long | Drops 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 ) → long | Selects and scrolls to the line at as_path WITHOUT raising an event (the app drove it) |
of_selected_path ( ) → string | The 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 ( ) → string | The 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 ( ) → long | Returns how many matches the current search found, read LIVE — the 12 of a 3 / 12 status line. 0 with no search |
of_match_index ( ) → long | Returns the 1-based position of the current match, read LIVE — the 3 of a 3 / 12 status line. 0 with no match |
Events #
| Event | When |
|---|---|
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 #
- It is a viewer, not an editor: it shows the XML, it does not change it. To read a value, take the path from
ue_node_clickedand fetch it in your own data. - A large XML folds:
of_collapse_allfirst, the reader opens what interests them — a thousand nodes open at once is unreadable. - Invalid XML breaks nothing:
ue_errorsays so, the tree stays empty. That is the feedback to show, not a crash.
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.
| Members | Role | Detailed in |
|---|---|---|
of_reset | Put the component back to zero | 3.6 Resetting a component: of_reset() |
of_register_shortcut · of_clear_shortcuts | The component's keyboard chords | 3.5 Keyboard shortcuts |
of_is_created · of_is_ready · of_get_last_error | Whether it was born, whether it is ready, what failed | 3.7 Diagnostics |
of_save_as_png · of_save_as_jpg | Export the rendering as an image | 3.8 Exporting the rendering as an image |
of_set_redraw | Group changes into a single repaint | 3.10 Best practices |
of_preload_icons | Icons shown with no delay | Instant display: of_icon |
of_set_translation | Translate one of the component's labels | 5.2 Adapting a label: of_set_translation |
of_focus_webview | Give the component the focus | 6.4 Keyboard and focus |
of_print · of_print_to_pdf | Print, or write a PDF | 6.9 Printing |
of_set_property · of_get_property · of_component_name | Driving a property by its name | 3.1 The property engine |