[racket] New users, XML, and xml/path

From: Greg Hendershott (greghendershott at gmail.com)
Date: Tue Jun 18 08:56:25 EDT 2013

I noticed a recent IRC exchange where someone was frustrated with
se-path*/list, and felt it didn't help enough compared to Python's
standard lib for this.[^1] They were trying to get the <row> elements
from an API like this[^2]:

<?xml version='1.0' encoding='UTF-8'?>
<eveapi version="2">
  <currentTime>2011-09-10 14:41:29</currentTime>
    <key accessMask="59760264" type="Character" expires="2011-09-11 00:00:00">
      <rowset name="characters" key="characterID"
        <row characterID="898901870" characterName="Desmont McCallock"
corporationID="1000009" corporationName="Caldari Provisions" />
  <cachedUntil>2011-09-10 14:46:29</cachedUntil>

Now, in the past I've dealt with XML by hand-coding, e.g. using
`match`. Which has worked fine for me. But I'd never really noticed
xml/path (was it added recently??) so I sat down to try it. Maybe I
should use that more. But a few things I noticed:

1. Name: Why the * in `se-path*` and `se-path*/list` names? By
convention this made me look for the non-* versions of these, which I
couldn't find.

2. Whitespace: When I try `(se-path*/list '(rowset) xe)` I get

'("\n        " (row ((characterID "898901870") (characterName "Desmont
McCallock") (corporationID "1000009") (corporationName "Caldari
Provisions"))) "\n      ")

Even with collapse-whitespace parameter set #t, I get

'(" " (row ((characterID "898901870") (characterName "Desmont
McCallock") (corporationID "1000009") (corporationName "Caldari
Provisions"))) " ")

I understand why, and what to do about it. But I'm not sure about a
new user. Probably I would instead try the following...

3. Can't get elements with their attributes:  If I try `(se-path*/list
'(rows) xe)` I get back '(). Huh.  I guess that's because the <row>
elements have empty bodies -- the interesting stuff is in their
attributes. OK, but I don't see how to get the element with attributes
conveniently, using xml/path.

Although I'm not very familiar with XPath, I think there probably is a
role for something simpler than it, provided with Racket itself, and
xml/path is a good idea. Does it make sense to enhance it just a bit
more, though?

p.s. If the original author of xml/path can't or doesn't want to do
this, I'd volunteer to take a shot and create a pull request. However
I know so little about XPath, I'm not sure whether that makes me the
best or worst person to be doing this (I'm mostly not joking).

[1]: http://docs.python.org/2/library/xml.etree.elementtree.html
[2]: http://wiki.eve-id.net/APIv2_Account_APIKeyInfo_XML

Posted on the users mailing list.