Re: [xml] seeking help with namespaces and SAX


On Fri, 2002-01-11 at 03:18, Daniel Veillard wrote:
I was essentially thinking that I would keep an array of lists of valid
namespace prefixes (one entry in the array for each parent node).  I
would walk up the array looking for the current element/attributes'
prefix.  On startElement the index into the array would be incremented,
and an array constructed of new prefixes for my namespace.  The reverse
would happen on endElement.  

  More complex than that, I think you need one dictionary per level.
Well you need at least to keep all the informations from the parents
nodes, including their level.

Ya, I decided (about 5 minutes after sending the mail :) on using a
sparse array, with one entry for each node which has namespace
definitions.  Each sparse array element contains a dictionary of
prefixes defined (and an entry for the default namespace if defined) on
the node.  The value of each entry being a boolean marking whether the
prefix represents my blessed namespace.

On startElement, I first iterate the namespace attributes adding their
prefixes to a new entry in the sparse array. If none are present, I
increment the reference count in the last entry in the sparse array. 
Then to check if a given attribute or element is in my namespace, I walk
up the sparse array looking in each dictionary for the first prefix that
matches (handling the default namespace as well).

On endElement I decrement the last sparse array entry's refcnt, and free
the prefix dictionary if it drops to zero.

Hmm... this doesn't cover the redefine of a parent node's valid prefix
to another namespace... uggg... I guess I could keep an allow list and a
deny list for each node.  Anyways, every way I can think of seems gross
and makes way too many allocations.  

A child node can remove a prefix from the subtree scope by using
    xmlns:foo = ""
or simply redefine foo to a new value (same applies to default namespaces too)
so you can't just pass the same array/dictionary underneath.

Good to know about the removal from scope.  Though my code handles this
already as "" doesn't match "my-special-namespace".

  The spec is short. You should read it.

Bah! Why do that when I can base my code on purely empirical data! ;-)

(thanks for the url)


 Think about it man!  Rock singers are only rockin you half the time... 
 the other time they're... they're breathing... in!  But not anymore 

                        -- Tenacious D

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]