Re: [xml] seeking help with namespaces and SAX



On Thu, Jan 10, 2002 at 11:04:44PM -0500, Alex Graveley wrote:
Hi,

I need to be able to tell if an element or attribute is in a specific
namespace using the SAX parser.  Is there any good sample code for a
state machine that would do this?

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.

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.

  The spec is short. You should read it.
    http://www.w3.org/TR/REC-xml-names/

Someone must have dealt with this before, whats the best solution?

Look in the Java code, they tend to use SAX a lot.

Daniel

-- 
Daniel Veillard      | Red Hat Network https://rhn.redhat.com/
veillard redhat com  | libxml Gnome XML XSLT toolkit  http://xmlsoft.org/
http://veillard.com/ | Rpmfind RPM search engine http://rpmfind.net/



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