<div dir="ltr"><div><div>Hi Jay,<br><br></div>thanks for your reply.<br><br>Unfortunately I can't find a way in my code to detect that in the resulting list from se-path*/list<br><br> '("Derek " "&" " the Dominos" "Nick Cave " "&" " the Bad Seeds")<br>
<br></div><div>the first three elements should be actually treated as a single string and so the last three.<br></div><div><br></div><div>Is there a common idiom in Racket to extract a list of values from an XML
collection, in a way that works with & and other entities?<br><br></div><div>Thanks in advance.</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Mon, Dec 2, 2013 at 9:27 PM, Jay McCarthy <span dir="ltr"><<a href="mailto:jay.mccarthy@gmail.com" target="_blank">jay.mccarthy@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Giacomo,<br>
<br>
First, the question is not really about se/list, because if you look<br>
at the xexpr you're giving it, the "name" node has three string<br>
children:<br>
<br>
'(bands () (name () "Derek " "&" " the Dominos") (name () "Nick Cave "<br>
<div class="im">"&" " the Bad Seeds"))<br>
<br>
</div>And se/list* gives you these children all appended together. If you<br>
got the name nodes themselves, then you could concatenate their<br>
children.<br>
<br>
Second, there real question is about why parsing XML works like that.<br>
If you look at this:<br>
<br>
(define xs<br>
<div class="im"> "<bands><name>Derek & the Dominos</name><name>Nick Cave &<br>
</div>the Bad Seeds</name></bands>")<br>
(define x<br>
(read-xml/document (open-input-string xs)))<br>
x<br>
<br>
Then you'll see that the core is that name doesn't have a single piece<br>
of PCDATA. It has three, one of which is an entity.<br>
<br>
I don't consider this an error in the XML parser, but a consequence of<br>
XML entities that might not be obvious: they are their only nodes in<br>
the list of children of the parent node.<br>
<br>
Jay<br>
<div><div class="h5"><br>
<br>
On Sun, Dec 1, 2013 at 8:36 AM, Giacomo Ritucci<br>
<<a href="mailto:giacomo.ritucci@gmail.com">giacomo.ritucci@gmail.com</a>> wrote:<br>
> Hi Racket Users,<br>
><br>
> I'm using se-path*/list to extract values from an XML collection but I found<br>
> a strange behaviour when the extracted values contain entities.<br>
><br>
> For example, given the following XML:<br>
><br>
> <bands><br>
> <name>Derek & the Dominos</name><br>
> <name>Nick Cave & the Bad Seeds</name><br>
> </bands><br>
><br>
> when I extract a list of band names with (se-path*/list '(name) xe) I'd<br>
> expect this result:<br>
><br>
> '("Derek & the Dominos" "Nick Cave & the Bad Seeds")<br>
><br>
> but what I actually receive is:<br>
><br>
> '("Derek " "&" " the Dominos" "Nick Cave " "&" " the Bad Seeds")<br>
><br>
> Is this the intended behaviour? How can I overcome this and make<br>
> se-path*/list return one string for tag?<br>
><br>
> Here's my test code, I'm running Racket v5.3.6 on Linux x86_64 and maybe I'm<br>
> doing overlooking something because I'm new to Racket.<br>
><br>
> Thank you in advance!<br>
><br>
> Best regards,<br>
> Giacomo<br>
><br>
> #lang racket<br>
><br>
> (require xml<br>
> xml/path)<br>
><br>
> (define xe (string->xexpr "<bands><name>Derek & the<br>
> Dominos</name><name>Nick Cave & the Bad Seeds</name></bands>"))<br>
><br>
> (module+ test<br>
> (require rackunit)<br>
><br>
> ;; what I get<br>
> (check-equal? (se-path*/list '(name) xe)<br>
> '("Derek " "&" " the Dominos" "Nick Cave " "&" " the Bad<br>
> Seeds"))<br>
><br>
> ;; what I'd expect<br>
> (check-equal? (se-path*/list '(name) xe)<br>
> '("Derek & the Dominos" "Nick Cave & the Bad Seeds")))<br>
><br>
</div></div>> ____________________<br>
> Racket Users list:<br>
> <a href="http://lists.racket-lang.org/users" target="_blank">http://lists.racket-lang.org/users</a><br>
><br>
<span class="HOEnZb"><font color="#888888"><br>
<br>
<br>
--<br>
Jay McCarthy <<a href="mailto:jay@cs.byu.edu">jay@cs.byu.edu</a>><br>
Assistant Professor / Brigham Young University<br>
<a href="http://faculty.cs.byu.edu/~jay" target="_blank">http://faculty.cs.byu.edu/~jay</a><br>
<br>
"The glory of God is Intelligence" - D&C 93<br>
</font></span></blockquote></div><br></div>