Name

The NamespaceSupport Class

Synopsis

NamespaceSupport provides a stack that can track the namespaces in scope at various points in the document. To use it, push a new context at the beginning of each element’s namespace mappings, and pop it at the end of each element. Each startPrefixMapping( ) invocation should call declarePrefix( ) to add a new mapping to the NamespaceSupport object. Then at any point where you need to figure out to which URI a prefix is bound, you can call getPrefix( ). The empty string indicates the default namespace. The getter methods can then tell you the prefix that is mapped to any URI or the URI that is mapped to any prefix at each point in the document. If you reuse the same NamespaceSupport object for multiple documents, be sure to call reset( ) between documents.

package org.xml.sax.helpers;
     
public class NamespaceSupport {
     
 public final static String XMLNS="http://www.w3.org/XML/1998/namespace";
     
  public NamespaceSupport(  );
     
  public void        reset(  );
  public void        pushContext(  );
  public void        popContext(  );
  public boolean     declarePrefix(String prefix, String uri);
  public String[  ]    processName(String qualifiedName, String[  ] parts,
   boolean isAttribute);
  public String      getURI(String prefix);
  public Enumeration getPrefixes(  );
  public String      getPrefix(String uri);
  public Enumeration getPrefixes(String uri);
  public Enumeration getDeclaredPrefixes(  );
     
}

Get XML in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.