25 May 2012 12:28
Exported symbols [was: Re: Possible bug in cxml-stp]
Raymond Wiker <rwiker <at> gmail.com>
2012-05-25 10:28:59 GMT
2012-05-25 10:28:59 GMT
On Wed, May 23, 2012 at 12:02 AM, David Lichteblau <david <at> lichteblau.com> wrote:
[Subject: changed, as it was getting embarassingly inappropriate.]
I ended up modifying my add-element function, based on the code that you included earlier. It now looks like this:
(defun add-element (parent element-name attributes &optional element-value)
(let ((element-name (if (listp element-name) (first element-name) element-name))
(namespace-uri (if (listp element-name) (second element-name)
(cxml-stp:find-namespace (cxml::split-qname element-name) parent))))
(let ((new-element (cxml-stp:make-element element-name namespace-uri)))
(cxml-stp:append-child parent new-element)
(loop for (name value) on attributes by #'cddr
do (cxml-stp:add-attribute
new-element
(cxml-stp:make-attribute
(princ-to-string value)
name
(cxml-stp-impl::find-attribute-namespace
(cxml::split-qname name) new-element))))
(when element-value
(cxml-stp:append-child new-element (cxml-stp:make-text (princ-to-string element-value))))
new-element)))
This seems to work, but I'm not 100% sure of the code that handles namespaces for attributes.
Note that the code uses two un-exported symbols: cxml::split-name and cxml-stp-impl::find-attribute-namespace. Should these be exported?
Best Regards,
Raymond Wiker
Quoting Raymond Wiker (rwiker <at> gmail.com):Possibly... cxml currently has such a macro only for its serialization
> Would it be an idea to add functionality similar to what
> plexippus-xpath provides via with-namespaces? I.e, a special variable
> that holds the current set of namespace tag/uri mappings, and have
> some some additional constructors that use split-qname to extract the
> tag and look-up the url from the current set of mappings.
API, i.e.
CL-USER> (cxml:with-xml-output (stp:make-builder)
(cxml:with-namespace ("a" "http://a")
(cxml:with-element "a:b"
(cxml:text "xyz"))))
#.(CXML-STP-IMPL::DOCUMENT
:CHILDREN '(#.(CXML-STP:ELEMENT
#| :PARENT of type DOCUMENT |#
:CHILDREN '(#.(CXML-STP:TEXT
#| :PARENT of type ELEMENT |#
:DATA
"xyz"))
:LOCAL-NAME "b"
:NAMESPACE-PREFIX "a"
:NAMESPACE-URI "http://a")))
That API can't really modify STP in place though; the builder only knows
how to set up a full document.
[Subject: changed, as it was getting embarassingly inappropriate.]
I ended up modifying my add-element function, based on the code that you included earlier. It now looks like this:
(defun add-element (parent element-name attributes &optional element-value)
(let ((element-name (if (listp element-name) (first element-name) element-name))
(namespace-uri (if (listp element-name) (second element-name)
(cxml-stp:find-namespace (cxml::split-qname element-name) parent))))
(let ((new-element (cxml-stp:make-element element-name namespace-uri)))
(cxml-stp:append-child parent new-element)
(loop for (name value) on attributes by #'cddr
do (cxml-stp:add-attribute
new-element
(cxml-stp:make-attribute
(princ-to-string value)
name
(cxml-stp-impl::find-attribute-namespace
(cxml::split-qname name) new-element))))
(when element-value
(cxml-stp:append-child new-element (cxml-stp:make-text (princ-to-string element-value))))
new-element)))
This seems to work, but I'm not 100% sure of the code that handles namespaces for attributes.
Note that the code uses two un-exported symbols: cxml::split-name and cxml-stp-impl::find-attribute-namespace. Should these be exported?
Best Regards,
Raymond Wiker
RSS Feed