You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-- Parse XML and extract information using tree queries
export func main() -> int ! {IO} {
let xml = "<catalog><book id=\"1\"><title>AILANG Guide</title><author>Claude</author></book><book id=\"2\"><title>Functional Design</title><author>AI</author></book></catalog>";
match parse(xml) {
Ok(root) => {
-- Find all book elements
let books = findAll(root, "book");
println("Found books:");
-- Find first title element
match findFirst(root, "title") {
Some(titleNode) => {
let titleText = getText(titleNode);
println(titleText)
},
None => println("No title found")
};
-- Get tag name of root (returns string, empty for non-Element)