> On Nov 21, 2019, at 9:51 AM, Kira <peacekeeperat...@gmail.com> wrote:
> 
> I tested sxml. And it is producer rigth (for me) output.
> 
> I feel that this is wrong behavior. Because this &quot; symbols is direct 
> part of one and whole element content. And must be read as "\"test qoute\"".
> 
> Can please someone explain reasoning under such behaivor, and can we change 
> it? Perhaps it is important for some other racket libs?
> It is just totally contrintuitive for me. And creating a huge problems with 
> even simple XML parsing. (I am basically battling XML lib all day already to 
> do most simple tasks)



If you want string elements to be concatenated where possible, you can do that 
after you parse:

#lang racket
(require xml txexpr rackunit)
(check-equal?
 (let loop ([x (string->xexpr "<ROOT><A><B1>test</B1><B2>&quot;test 
qoute&quot;</B2></A></ROOT>")])
   (match x
     [(txexpr tag attrs elements) (txexpr tag attrs (loop elements))]
     [(list (? string? strs) ..1 xs ...) (cons (string-join strs "") (loop xs))]
     [(list xs ...) (map loop xs)]
     [x x]))
 '(ROOT (A (B1 "test") (B2 "\"test qoute\""))))


But AFAIK there is nothing in the XML spec that requires XML to be parsed in 
your preferred style. So it is not "wrong behavior". 

Moreover, if you are writing code that treats '(tag "a" "b") and '(tag "ab") as 
semantically distinct, that's a code smell, because as XML, they're equivalent:

#lang racket
(require xml rackunit)
(check-equal? "<tag>ab</tag>" (xexpr->string '(tag "a" "b")))
(check-equal? "<tag>ab</tag>" (xexpr->string '(tag "ab")))

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/04CAA36E-F8D8-479D-9509-28A2970DB445%40mbtype.com.

Reply via email to