GOLF(2gg)

πŸ“¦ version 601.4.41, in ubuntu questing

πŸ’… GOLF(2gg) β€” the read-xml era πŸŽ€

okay bestie, sit down, hydrate, because we're about to read some XML and it's gonna be so good. this is page two of the GOLF manual, from the Development chapter, and it's giving parser main character energy ✨


🌸 NAME 🌸

read-xml β€” no literally that's it, that's the name, and the parenthetical vibe is (XML-parsing) πŸ¦‹


🎯 PURPOSE 🎯

Read data elements from an XML document. that's the whole assignment, and it ate πŸ’…


✨ SYNTAX ✨

read-xml <xml> \
    [ key <key> ] \
    [ value <value> ] \
    [ status <status> ] \
    [ next ]

look at those optional clauses just hanging out in there, being all [ ] and mysterious. iconic behavior honestly πŸ‘‘


πŸ’– DESCRIPTION πŸ’–

so read-xml reads data elements out of the <xml> variable, and heads up β€” that variable is created with xml-doc, not by you, not by me, by xml-doc. 🫢

A data element is a string <key>/<value> pair. and what's the key, you ask? the key (the one in the "key" clause) is a normalized key name, which means it's the current name preceded with the names of all the elements leading up to it, all separated by a forward slash ("/"). very "here's my whole ancestry" of it. and note that attribute elements end with "@" β€” that's the little tell that says "hi, I'm an attribute, not an element" πŸŽ€

The actual <value>? you grab that with the "value" clause. the <status>? that's the "status" clause's job. and what does status say?

  • <status> is GG_OKAY if the key/value is obtained βœ…
  • <status> is GG_ERR_EXIST if there are no more to get πŸ’€

Use the "next" clause to move to the next sequential key/value pair in the document, going from top down as available. so the typical lil routine is: get a key first, look at it, decide if it's of interest to you (vibe check 🧚), and then obtain the value. and yes, you can absolutely use "key", "value" and "next" all at the same time if you're going through all the elements β€” go off, thorough queen 🌈

now, <key> in the "key" clause is a normalized name of any given element in the XML text. that means:

  • every non-leaf element is included, separated by a forward slash ("/")
  • and arguments end with "@"

for example, if "onclick" is an element of "menuitem":

menu/popup/menuitem/onclick

or, if "onclick" is an attribute of "menuitem":

menu/popup/menuitem/onclick/@

see that lil @ at the end? that's the whole difference. no cap. ⭐


πŸ“ EXAMPLES πŸ“

See xml-doc. that's the example. short and sweet, she's efficient πŸ’œ


πŸ‘€ SEE ALSO πŸ‘€

  • XML parsing
  • read-xml
  • xml-doc
  • See all documentation

lowkey reminder from your girl: this page is GOLF(2gg) from the Development section, so if you're lost, you're lost in the right place bestie πŸ¦‹

and that's the whole page!! this manual was dated $DATE, version $VERSION, and it lives in the GOLF(2gg) section. mwah, go parse something gorgeous πŸ’–βœ¨πŸŽ€

πŸ“¦ where this page comes from