On May 22, 2012, at 16:46 , rm@tuxteam.de wrote:
On Tue, May 22, 2012 at 03:35:30PM +0200, David Lichteblau wrote:
Quoting Raymond Wiker (rwiker@gmail.com):
I was confused about empty namespace uris vs empty namespace tags - I wanted to create nodes that would be in the same namespace as their parent, but I now see why that would be problematic.
Thank you for your patience.
So STP doesn't have a built-in feature for this, but I suppose a helper function could be nice for this purpose. Maybe something like this:
CL-USER> (defun make-element-in-context (qname context) (stp:make-element qname (stp:find-namespace (cxml::split-qname qname) context))) MAKE-ELEMENT-IN-CONTEXT
CL-USER> (stp:make-element "test" "http://bar") #.(CXML-STP:ELEMENT :LOCAL-NAME "test" :NAMESPACE-URI "http://bar")
CL-USER> (make-element-in-context "child" *) #.(CXML-STP:ELEMENT :LOCAL-NAME "child" :NAMESPACE-URI "http://bar")
Well, since the OP already uses a wrapper function to add elements this isn't neccessary. And I think the underlying confusion came from the (wrong) assumption that an empty namespace (i.e. ns-uri = "") would mean "same ns as parent". That's a rather common misconception stemming from the difference between the xml data model and it's serialisaton. Namespace prefixes belong to the later. BTW: why are you using split-qname in your wrapper? Would you expect to feed "foo:bar" to make-element-in-context?
Thank you both for your suggestions, they will be useful to me when I rewrite my code.
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.
Then again, the reason I wrote add-element was to provide an abstraction for the operation of creating a new element with (optional) attributes and (optional) text content and adding it to a parent node. Implementing a mapping mechanism between qnames and uris will not help with this.