Class XMLNamespaceParser

java.lang.Object
org.xml.sax.helpers.DefaultHandler
edu.ucsb.nceas.metacat.service.XMLNamespaceParser
All Implemented Interfaces:
ContentHandler, DTDHandler, EntityResolver, ErrorHandler

public class XMLNamespaceParser extends DefaultHandler
This class will parse the root element to figure out the namespace of the root element(we also call it the namespace of the element). If it doesn't have a namespace, but it does have an attribute of noNamespaceSchemaLocation at the root element, it will get the value as well.
Author:
tao
  • Constructor Details

    • XMLNamespaceParser

      public XMLNamespaceParser(Reader xml) throws SAXException, edu.ucsb.nceas.utilities.PropertyNotFoundException
      Constructor
      Parameters:
      xml - the xml object which will be parsed
      Throws:
      SAXException
      edu.ucsb.nceas.utilities.PropertyNotFoundException
  • Method Details

    • parse

      public void parse() throws SAXException, IOException
      Parse the xml file
      Throws:
      SAXException - if some sax related exception happens
      IOException - if the schema content couldn't be found
    • startElement

      public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException
      SAX Handler that is called at the start of each XML element
      Specified by:
      startElement in interface ContentHandler
      Overrides:
      startElement in class DefaultHandler
      Throws:
      SAXException
    • getNamespace

      public String getNamespace()
      Get the namespace of the document (root element). The parse() method should be called first
      Returns:
      the value of the namespace. A null will be returned if it can't be found.
    • getNoNamespaceSchemaLocation

      public String getNoNamespaceSchemaLocation()
      Get the value of noNamespaceSchemaLocation of the document (root element). The parse() method should be called first
      Returns:
      the value of the noNamespaceSchemaLocation. A null will be returned if it can't be found.