Code example for NamespaceSupport

Methods: pushContext

0
    String     namespaceURI,
    String     localName,
    String     qualifiedName,
    Attributes attributes) throws SAXException
  { 
    namespaces.pushContext();
    // support both DTD and Schema 
    if (namespaceURI.equals(XINCLUDE_NAMESPACE) &&
        localName.equals("include"))
    { 
      // href attribute is required 
      String href = attributes.getValue("href");
      if (href == null)
        throw new SAXException("Missing href attribute");
 
      // xpointer attribute is optional 
      String xpointer = attributes.getValue("xpointer");
 
      doXInclude(href, xpointer);
    } 
    else 
    { 
      super.startElement(namespaceURI, localName, qualifiedName, attributes);
    } 
  } 
 
  public void endElement( 
    String     namespaceURI,
    String     localName,
    String     qualifiedName) throws SAXException
  { 
    if (!namespaceURI.equals(XINCLUDE_NAMESPACE))
      super.endElement(namespaceURI, localName, qualifiedName);
 
    namespaces.popContext();
  } 
 
  public void startDocument() throws SAXException 
  { 
    if (depth == 0)
      super.startDocument(); 
 
    depth++;
  } 
 
  public void endDocument() throws SAXException 
  { 
    locators.pop();
    depth--;
 
    if (depth == 0)
      super.endDocument(); 
  } 
 
  private void doXInclude( 
    String href,
    String xpointer) throws SAXException
  { 
    URL target = resolveURL(href);
 
    try 
    { 
      SAXParserFactory saxFactory = SAXParserFactory.newInstance();
      SAXParser saxParser = saxFactory.newSAXParser();
      XMLReader reader = saxParser.getXMLReader();
      if (xpointer != null)
      { 
        // pass all parsed SAX events through XPointerFilter 
        reader = new XPointerFilter(reader, namespaces, xpointer);
      } 
      // pass all selected XPointer SAX events to XIncludeFilter 
      reader.setContentHandler(this);
      reader.setEntityResolver(this);
      reader.setErrorHandler(this);
Contextual code suggestions in your IDE  Get Codota for Java