[cxml-devel] Bugs in namespace parsing.

Peder Chr. Nørgaard pcn at pogt.dk
Mon May 21 20:47:30 UTC 2007


I think I have run into a pretty bad bug in namespace handling in Closure XML.  
Of course, I may just be using the code wrongly.

I am using the 2007-02-18 tarball of cxml on a piece of XML code from
RFC 4741 (netconf protocol):

(defvar example "<rpc message-id=\"101\"
          xmlns=\"urn:ietf:params:xml:ns:netconf:base:1.0\">
       <my-own-method xmlns=\"http://example.net/me/my-own/1.0\">
         <my-first-parameter>14</my-first-parameter>
         <another-parameter>fred</another-parameter>
       </my-own-method>
     </rpc>")


I run

(defvar p-example  (cxml:parse-stream (make-string-input-stream example)    		
cxml-xmls:make-xmls-builder)))


This is the result:

(("rpc"
  (("xmlns" "urn:ietf:params:xml:ns:netconf:base:1.0") ("message-id" "101")) "
       "
  ("my-own-method" (("xmlns" "http://example.net/me/my-own/1.0")) "
         "
   ("my-first-parameter" NIL "14") "
         "
   ("another-parameter" NIL "fred") "
       ")
  "
     "))


It should have been something like

((("rpc" . "urn:ietf:params:xml:ns:netconf:base:1.0")
  (("xmlns" "urn:ietf:params:xml:ns:netconf:base:1.0") 
   (("message-id" . "urn:ietf:params:xml:ns:netconf:base:1.0") "101")) "
       "
  (("my-own-method" . "http://example.net/me/my-own/1.0")
   (("xmlns" "http://example.net/me/my-own/1.0")) "
         "
   (("my-first-parameter" . "http://example.net/me/my-own/1.0) NIL "14") "
         "
   (("another-parameter" . "http://example.net/me/my-own/1.0) NIL "fred") "
       ")
  "
     "))

There seems to be not one, but two problems.  First, the parser or the builder 
ignores the rule that the scope of an xmlns attribute starts from the tag of 
the element in which it is included.  Second, (and that is probably the 
builder) fail to apply the default namespace to internal elements.

FYI, XMLS has the approximately the same kind of bug.  So has the PXML suite 
from Franz.  It is evidently something that is a bit tough to get right.  
Maybe because it involves two scans of a <> construction - you really don't 
know the namespace of tags and attributes until you have parsed the entire <> 
construction and located the zero-or-one "xmlns=" and the 
zero-one-or-many "xmlns:<name>=" attributes.


best regards
-- 
Peder Chr. Nørgaard     e-mail: pcn at pogt.dk
Gefionsvej 19           spejder-e-mail: hathi at gallerne.dk
DK-8230 Åbyhøj          tel: +45 87 44 11 99
Denmark                 mob: +45 30 91 84 31



More information about the cxml-devel mailing list