chicken-users
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Chicken-users] Lowdown & sxml-serializer not working together


From: Jim Ursetto
Subject: Re: [Chicken-users] Lowdown & sxml-serializer not working together
Date: Sat, 24 Aug 2013 17:25:55 -0500

On Aug 23, 2013, at 11:24 PM, Matt Gushee <address@hidden> wrote:

> Hello again--
> 
> Well, I'm running into a new problem with SRV:send-reply. By following
> the documentation, I managed to create a rule set that escaped problem
> characters i the manner I want. But now, working with the complete
> document, I discover that some of the non-element nodes are not
> handled properly. The SXML form of my document starts like this:
> 
>  (*TOP*
>    (@ (*NAMESPACES*
>      (#f "http://www.w3.org/1999/xhtml";)
>      (cvt "http://xmlns.therebetygers.net/civet/0.1";)))
>    (*PI* xml "version=\"1.0\" encoding=\"utf-8\"")
>    (html
>      (@ (xml:lang "en") (lang "en"))
> 
> But when I serialize it with (SRV:send-reply (pre-post-order tree
> <rules>)), the output begins like this:
> 
>  <*TOP*
>      *NAMESPACES*="http://www.w3.org/1999/xhtml
>       cvt="http://xmlns.therebetygers.net/civet/0.1"";>
>  <*PI*>xmlversion=&quot;1.0&quot; encoding=&quot;utf-8&quot;</*PI*>
>  <html xml:lang="en" lang="en">

This should serialize reasonably correctly with sxml-serializer.

(use sxml-serializer)

(print
 (serialize-sxml
 '(*TOP*
   (@ (*NAMESPACES*
       (#f "http://www.w3.org/1999/xhtml";)
       (cvt "http://xmlns.therebetygers.net/civet/0.1";)))
   (*PI* xml "version=\"1.0\" encoding=\"utf-8\"")
    (html
     (@ (xml:lang "en") (lang "en"))
     (cvt:template
      (cvt:head
       (cvt:locale (@ (lang "en") (country "US") (encoding "utf-8"))))
       (cvt:block (@ (name "headerContent"))
         #\< Single #\space (#\a #\r #\t #\i #\c #\l #\e) #\space "page>"))))))

<?xml version="1.0" encoding="utf-8"?>
<html xml:lang="en" lang="en">
  <cvt:template xmlns:cvt="http://xmlns.therebetygers.net/civet/0.1";>
    <cvt:head>
      <cvt:locale lang="en" country="US" encoding="utf-8" />
    </cvt:head>
    <cvt:block name="headerContent">&lt;Single article page&gt;</cvt:block>
  </cvt:template>
</html>

Unfortunately it doesn't declare the default namespace for html.  You can work 
around this by providing a default namespace prefix *and* using the actual 
prefix (below, xhtml:) on your elements.  This is kind of ugly.  However, the 
stock serializer didn't even support default namespaces (!) so I may have 
simply overlooked this case when adding support.  I'll see if I can look into 
it further.

(print
 (serialize-sxml
 '(*TOP*
   (@ (*NAMESPACES*
       (xh "http://www.w3.org/1999/xhtml";)
       (cvt "http://xmlns.therebetygers.net/civet/0.1";)))
   (*PI* xml "version=\"1.0\" encoding=\"utf-8\"")
    (xh:html
     (@ (xml:lang "en") (lang "en"))
     (cvt:template
      (cvt:head
       (cvt:locale (@ (lang "en") (country "US") (encoding "utf-8"))))
        (cvt:block (@ (name "headerContent"))
         #\< Single #\space (#\a #\r #\t #\i #\c #\l #\e)
         #\space "page>"))))
 ns-prefixes: '((*default* . "http://www.w3.org/1999/xhtml";))
  ))

<?xml version="1.0" encoding="utf-8"?>
<html xmlns="http://www.w3.org/1999/xhtml"; xml:lang="en" lang="en">
  <cvt:template xmlns:cvt="http://xmlns.therebetygers.net/civet/0.1";>
    <cvt:head>
      <cvt:locale lang="en" country="US" encoding="utf-8" />
    </cvt:head>
    <cvt:block name="headerContent">&lt;Single article page&gt;</cvt:block>
  </cvt:template>
</html>


Namespaces can be tricky.  Check my blog posts on the subject and feel free to
ask for help.

http://3e8.org/blog/2010/07/30/namespaces-in-sxml-part-1/
http://3e8.org/blog/2010/07/31/namespaces-in-sxml-part-2/
http://3e8.org/blog/2010/08/01/default-namespaces-in-sxml/

Jim


reply via email to

[Prev in Thread] Current Thread [Next in Thread]