OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   Re: SAX2: Interning names in namespaces

[ Lists Home | Date Index | Thread Index ]
  • From: terje@in-progress.com (Terje Norderhaug)
  • To: xml-dev@xml.org
  • Date: Sat, 5 Feb 2000 12:56:35 -0800

At 11:58 AM 2/5/00, Terje Norderhaug wrote:
>At 4:46 AM 2/5/00, Stefan Haustein wrote:
>>>
>>> PROPOSAL
>>>
>>> I suggest that parsers interns each name as a separate string in the
>>> namespace it belong to. This should guarantee that two equal names in the
>>> same namespace are identical, and that two equal names in different
>>> namespaces are unidentical.
>>
>>Sounds too complicated for broad acceptance [...]
>
>It is straight-forward to implement. Here is pseudo code for one possible
>implementation using hash tables:
>
>constant namespaces = make new hashtable with equality as test
>
>function internName (namestring, URI):
>  namespace = namespaces.find(URI)
>  if no namespace
>    namespace = make new hashtable with equality as test
>    namespaces.insert(URI, namespace)
>  end if
>  name = namespace.find(namestring)
>  if no name
>    name = namestring.copy
>    namespace.insert(name, name)
>  end if
>  return name
>end function

For those that prefer a working implementation to pseudo-code, here is the
same as above but implemented in ANSI Common LISP:

(defconstant namespaces (make-hash-table :test 'equal))

(defun intern-name (namestring URI)
  (let ((namespace (or (gethash URI namespaces)
                       (setf (gethash URI namespaces)
                         (make-hash-table :test 'equal)))))
    (or (gethash namestring namespace)
        (setf (gethash namestring namespace)
          (copy-seq namestring)))))

-- Terje <terje@in-progress.com> | Media Design in*Progress

   Software for Mac Web Professionals at <http://www.in-progress.com>
   Take advantage of XML with Emile, the first XML editor for Mac!






 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS