From: ser@... (Sean Russell) Date: 2003-06-28T04:30:34+09:00 Subject: Re: REXML and Namespaces. Aredridel wrote in message news:<1056644378.17774.30.camel@mizar>... > May I offer the suggestion of a "context" object that defines /all/ the > namespaces and mappings to their prefixes, and then, all one has to do > is: > > context = new Context({'foo', 'http://foo.org/b', > '', 'http://www.w3.org/somewhere'}) > context.do { > a = Element.new("foo:a") > b = a.add_element("b") > } > > the element "b" would get the w3.org namespace, and foo:a would get the > foo.org namespace. This is an interesting idea. I was thinking along the same lines, but with setting the context in the node tree itself: a = doc.add_element("a") # New element, no namespace a.define_namespace( "foo", "http://foo.org/b" ) # Assoc. namespace w/ prefix a.namespace = "http://foo.org/b" # Set a's namespace b = a.add_element("b") # Add b to a; no default (no) # namespace c = a.add_element("c", "http://x.org") # Add c to a in x.org namespace d = c.add_element("d") # Add d to c, in default (x.org) # namespace e = c.add_element("e", '') # Add e to c, w/ empty namespace My hesitation with doing things this way is that it marginalizes prefixes, which is how XML is defined. However, it is not the way people think about namespaces. It also hides the nature of default namespaces, which I really don't like. > A sidenote: Sean, I'd like to pick your brain some time, since I'm > planning to set up a way of indexing content of XML documents in a > separate index file, and it may make XPath searches much faster and add > the possibly of disk-based access instead of parse-whole-tree access of > docs for XPath. If you can think of a way to do this, I'd really like to hear about it. At one point I wrote a version of XPath that used indexed trees, in the hopes that I could speed it up. I discovered that the time consuming aspects of XPath are things that are not indexable: predicates. Predicates must be evaluated in the context of a node. Ironically, having to deal with namespaces also really slows down XPath searches. In the end, the cost of indexing a document offset any speed gains the indexing provided; in fact, for simple 'a/b' XPaths, the indexed version was only faster where the indexing cost was amortized over multiple searches. It sounds like you've got something in mind that bypasses parsing the XML document at all, which would be interesting; to be honest, I can't imagine how you could evaluate an XPath in that context, but feel free to email me about it -- I'd love to hear your ideas. --- SER