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