Skip to content

Commit

Permalink
add method for xml doc drilldown (#11258)
Browse files Browse the repository at this point in the history
  • Loading branch information
marthasharkey authored Oct 8, 2024
1 parent 6e11e6a commit 1ae6464
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
17 changes: 17 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Data/XML.enso
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,23 @@ type XML_Document
_ : Integer -> if key == 0 then self.root_element else if_missing
_ : Text -> if key == self.root_element.name then self.root_element else if_missing

## GROUP Selections
ICON parse3
Gets the child element of the inner XML Element

Arguments:
- key: If an `Integer`, returns the element at position `at` in its list
of children. If `Text`, then if starts with `"@"`, returns the
attribute with the given name otherwise returns the first child element
with the given name.

@key child_selector
get_child_element : Text | Integer -> Any | Text | XML_Element | Vector (Text | XML_Element) ! No_Such_Key | Index_Out_Of_Bounds | XML_Error
get_child_element self key:(Text | Integer)="." =
root = self.get 0
root.get key


## GROUP Selections
ICON parse3
Gets a child or attribute of an XML document.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ make_json_for_xml_element xml_element max_items type:Text="XML_Element" =
map_vector = Warning.clear (attribs + children)

data = ["data", [map_vector.map .first, map_vector.map .second, map_vector.map i-> i.at 2]]
get_child_node_fields = if type == "XML_Element" then [["get_child_node_action", "get"], ["get_child_node_link_name", "key"], ["link_value_type", "number"]] else []
get_child_node_fields = if type == "XML_Element" then [["get_child_node_action", "get"], ["get_child_node_link_name", "key"], ["link_value_type", "number"]] else [["get_child_node_action", "get_child_element"], ["get_child_node_link_name", "key"], ["link_value_type", "number"]]
JS_Object.from_pairs <| [header, data, all_rows, ["type", type]] + get_child_node_fields

## PRIVATE
Expand Down

0 comments on commit 1ae6464

Please sign in to comment.