|
1 | | -# XMLWalker |
2 | 1 |
|
3 | | -[](https://github.com/Manarom/XMLWalker.jl/actions/workflows/CI.yml?query=branch%3Amain) |
| 2 | + |
| 3 | +[](https://github.com/Manarom/XMLWalker.jl/actions/workflows/CI.yml?query=branch%3Amain) |
| 4 | + |
| 5 | +[](https://manarom.github.io/XMLWalker.jl) |
| 6 | + |
| 7 | +# XMLWalker.jl |
| 8 | + |
| 9 | +After loading the XML file using `XML.jl`, all data is stored in an encapsulated, tree-like structure of `Nodes`. Each node element has a children field, which is a vector of child `Nodes`, as well as other fields like `attributes`, `value` etc. `XMLWalker.jl` provides tools for traversing the XML tree using a set of matchers that check the content of nodes. Matchers can be created from strings and combined into chain strings, forming a sequence of matchers to find nodes that meet multiple content restrictions. The function `XMLWalker.find_nodes` converts input string to machers, recursively applies these matchers and returns a vector of nodes that satisfy the specified conditions. |
| 10 | + |
| 11 | +# Quick start |
| 12 | +```julia |
| 13 | +import Pkg |
| 14 | +Pkg.add("XMLWalker.jl") |
| 15 | + |
| 16 | +import XMLWalker |
| 17 | +import XML |
| 18 | + |
| 19 | +xml_file = XML.read(xml_file,Node) # loads data as a structure with multiple embedded nodes |
| 20 | +matched_nodes = XMLWalker.find_nodes(starting_node,"A/[B,C]/D") # finds nodes, matching the |
| 21 | +# specified path (chain) or single matching "A"=>"B"=>"D" or "A"=>"C"=>"D" route |
| 22 | +``` |
| 23 | +Search string can contain various elements like regular expressions, partial matching patterns, patterns unions and intersections, searching nodes by content etc. |
| 24 | + |
| 25 | +More complicated search examples: |
| 26 | +```julia |
| 27 | + XMLWalker.find_nodes(starting_node,"*/[[\\d]::regex].attributes({id,p1})/*/D") |
| 28 | + # will search for all subnodes of a starting_node that has: |
| 29 | + # - has field `tag` containing digits, |
| 30 | + # - field `attributes` with both "id" and "p1" keys |
| 31 | + # - any subnode |
| 32 | + # - sub-subnode with field tag equal to "D" |
| 33 | + XMLWalker.find_nodes(starting_node,"[ABC,BBB].parameters=[A,B,C]") # searches for the nodes that has "ABC" or "BBB" tag |
| 34 | + # and "A","B" or "C" values of `parameters` field |
| 35 | + XMLWalker.find_nodes(starting_node,"*.attributes({id,*par})",:Name) # searches for nodes with any Name field, but with |
| 36 | + # attributes field, which must have key "id" and any key which contains "par" as a substring |
| 37 | +``` |
| 38 | +It is also possible to create a matcher objects from string using `@to_matcher_str` macro. |
| 39 | +This macro can be usefull for multiple searches of the same pattern. |
| 40 | + |
| 41 | +```julia |
| 42 | + using XMLWalker |
| 43 | + matcher_object =XMLWalker.to_matcher"[[\\d]::regex].attributes({id,p1})" # returns matchers objects vector |
| 44 | + XMLWalker.find_nodes(starting_node1 , matcher_object[]) |
| 45 | + XMLWalker.find_nodes(starting_node2 , matcher_object[]) |
| 46 | +``` |
| 47 | +Full search string specification and package API are availabel at [documentation page](https://manarom.github.io/XMLWalker.jl/). |
| 48 | + |
0 commit comments