XML Expression Path Lookup
(require xexpr-path) | package: xexpr-path |
Utilities to find XML expression elements using a simple path.
value
Path is a list of components. A valid componenet can be:
| to match tag name, '* matches any tag | |
| to match an attribute | |
| to match tags with given attribute value |
procedure
(xexpr-path-list path xexpr) → (listof (or/c xexpr/c string?))
path : xexpr-path/c xexpr : xexpr/c
Elements can be matched using tag names.
> (xexpr-path-list '(greeting) '(greetings (greeting "Hello World!") (greeting "Ahoj Světe!"))) '((greeting "Hello World!") (greeting "Ahoj Světe!"))
In some cases, it can be handy to further filter the elements by values of their attributes.
> (xexpr-path-list '(value (type "int")) '(dataset (value ((type "int")) "42") (value ((type "str")) "foo") (value ((type "int")) "13"))) '((value ((type "int")) "42") (value ((type "int")) "13"))
procedure
(xexpr-path-first path xexpr) → (or/c xexpr/c string? #f)
path : xexpr-path/c xexpr : xexpr/c
> (xexpr-path-first '(item) '(items (item "one") (item "two"))) '(item "one")
> (xexpr-path-first '(item) '(items)) #f
procedure
(xexpr-path-text path xexpr) → (or/c string? #f)
path : xexpr-path/c xexpr : xexpr/c
Keep in mind that this function does not return plain string, but rather valid XML representation of the matched elements.
> (xexpr-path-text '(prop (id "name") *) '(object (prop ((id "kind")) "show") (prop ((id "name")) "Lucky" 9734 "Star"))) "Lucky☆Star"