RosettaCodeData/Task/XML-XPath/Bracmat/xml-xpath.bracmat

67 lines
1.4 KiB
Plaintext

{Retrieve the first "item" element}
( nestML$(get$("doc.xml",X,ML))
: ?
( inventory
. ?,? (section.?,? ((item.?):?item) ?) ?
)
?
& out$(toML$!item)
)
{Perform an action on each "price" element (print it out)}
( nestML$(get$("doc.xml",X,ML))
: ?
( inventory
. ?
, ?
( section
. ?
, ?
( item
. ?
, ?
( price
. ?
, ?price
& out$!price
& ~
)
?
)
?
)
?
)
?
|
)
{Get an array of all the "name" elements}
( :?anArray
& nestML$(get$("doc.xml",X,ML))
: ?
( inventory
. ?
, ?
( section
. ?
, ?
( item
. ?
, ?
( name
. ?
, ?name
& !anArray !name:?anArray
& ~
)
?
)
?
)
?
)
?
| out$!anArray {Not truly an array, but a list.}
);