From: Sjoerd Mullender Date: Thu, 31 Aug 2000 10:27:00 +0000 (+0000) Subject: New method getnamespace. X-Git-Tag: v2.0b1~140 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1c8feae411a8afda43e903e5c202ea0e1dbcacbf;p=python New method getnamespace. Since the application never gets to see the namespace abbreviation used in the XML document, but some applications may need to know them, we provide this method. --- diff --git a/Doc/lib/libxmllib.tex b/Doc/lib/libxmllib.tex index 62fb26b746..10d76ec36c 100644 --- a/Doc/lib/libxmllib.tex +++ b/Doc/lib/libxmllib.tex @@ -92,6 +92,11 @@ Translate all entity and character references in \var{data} and return the translated string. \end{methoddesc} +\begin{methoddesc}{getnamespace}{} +Return a mapping of namespace abbreviations to namespace URIs that are +currently in effect. +\end{methoddesc} + \begin{methoddesc}{handle_xml}{encoding, standalone} This method is called when the \samp{} tag is processed. The arguments are the values of the encoding and standalone attributes diff --git a/Lib/xmllib.py b/Lib/xmllib.py index 06b599fa76..b8422cb450 100644 --- a/Lib/xmllib.py +++ b/Lib/xmllib.py @@ -222,6 +222,13 @@ class XMLParser: else: i = s + len(str) + # Interface - return a dictionary of all namespaces currently valid + def getnamespace(self): + nsdict = {} + for t, d, nst in self.stack: + nsdict.update(d) + return nsdict + # Internal -- handle data as far as reasonable. May leave state # and data to be processed by a subsequent call. If 'end' is # true, force handling all data as if followed by EOF marker.