xmlutils and xmlns scope
Marco Baringer <[email protected]> Tue, 17 Feb 2004 17:37:12 +0100
| Newsgroups | gmane.lisp.open-source.franz |
|---|---|
| Message-ID | <[email protected]> |
--Apple-Mail-4--55615446
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
xmlutils' xml parser does not properly apply the scope of xmlns
declarations.
parsing this: <a xmlns="http://foo.com"/> shourd considre the tag a to
be in the namespace http://foo.com, currently xmlutils will only apply
the namespace to tokens later than (textually) the xmlns declaration.
xmlutils also removes the namspaces before parsing the closing tag
name, it should do this aferwards.
the attached patch may not be the cleanest way of fixing this problem,
but it works.
--Apple-Mail-4--55615446
Content-Disposition: attachment;
filename=pxml2.cl.patch
Content-Transfer-Encoding: 7bit
Content-Type: application/octet-stream;
x-unix-mode=0644;
name="pxml2.cl.patch"
--- orig/pxml2.cl
+++ mod/pxml2.cl
@@ -882,6 +882,9 @@
then (add-to-coll coll ch)
elseif (eq #\> ch) then
(let ((tag-string (compute-coll-string coll)))
+ (setq tag-to-return (compute-tag coll *package*
+ (iostruct-ns-to-package tokenbuf)))
+ ;; remove the namespaces introduced by this tag
(when (and (iostruct-ns-scope tokenbuf)
(string= tag-string
(first (first (iostruct-ns-scope tokenbuf)))))
@@ -891,8 +894,6 @@
(iostruct-ns-to-package tokenbuf))))
(setf (iostruct-ns-scope tokenbuf)
(rest (iostruct-ns-scope tokenbuf)))))
- (setq tag-to-return (compute-tag coll *package*
- (iostruct-ns-to-package tokenbuf)))
(return)
elseif (xml-space-p ch) then (setf state state-readtag-end3)
(let ((tag-string (compute-coll-string coll)))
@@ -1172,7 +1173,7 @@
:end1 5))
(if* (= (length name) 5)
then
- (setf ns-token :none)
+ (setf ns-token :none)
elseif (eq (schar name 5) #\:)
then
(setf ns-token (subseq name 6)))))
@@ -1283,6 +1284,24 @@
(return new-package)))))))
(setf (iostruct-ns-to-package tokenbuf)
(acons ns-token package (iostruct-ns-to-package tokenbuf)))
+ ;; reparse the tag-to-return and
+ ;; attribs-to-return in the new namespaces
+ (let ((temp-collector (get-collector)))
+ (flet ((make-temp-collector (string)
+ (map-into (collector-data temp-collector)
+ #'identity string)
+ (setf (collector-next temp-collector) (length string))
+ temp-collector))
+ (setf tag-to-return (compute-tag (make-temp-collector tag-to-return-string)
+ *package*
+ (iostruct-ns-to-package tokenbuf)))
+ (setf attribs-to-return
+ (loop
+ for (value name) on attribs-to-return by #'cddr
+ collect value
+ collect (compute-tag (make-temp-collector (symbol-name name))
+ *package*
+ (iostruct-ns-to-package tokenbuf))))))
)
(if* (and (first (iostruct-ns-scope tokenbuf))
(string= (first (first (iostruct-ns-scope tokenbuf)))
--Apple-Mail-4--55615446
Content-Transfer-Encoding: 7bit
Content-Type: text/plain;
charset=US-ASCII;
format=flowed
--
Marco
Ring the bells that still can ring.
Forget the perfect offering.
There is a crack in everything.
That's how the light gets in.
-Leonard Cohen
--Apple-Mail-4--55615446--