edu.ucsb.nceas.metacat.service

## Class XMLNamespaceParser

- java.lang.Object
- - org.xml.sax.helpers.DefaultHandler
  - - edu.ucsb.nceas.metacat.service.XMLNamespaceParser

- All Implemented Interfaces:
    org.xml.sax.ContentHandler, org.xml.sax.DTDHandler, org.xml.sax.EntityResolver, org.xml.sax.ErrorHandler

      public class XMLNamespaceParser
      extends org.xml.sax.helpers.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 Summary

    Constructors
    Constructor and Description
    `XMLNamespaceParser(java.io.Reader xml)` Constructor

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `java.lang.String` | `getNamespace()` Get the namespace of the document (root element).
    `java.lang.String` | `getNoNamespaceSchemaLocation()` Get the value of noNamespaceSchemaLocation of the document (root element).
    `void` | `parse()` Parse the xml file
    `void` | `startElement(java.lang.String uri, java.lang.String localName, java.lang.String qName, org.xml.sax.Attributes atts)` SAX Handler that is called at the start of each XML element

    - ### Methods inherited from class org.xml.sax.helpers.DefaultHandler

      `characters, endDocument, endElement, endPrefixMapping, error, fatalError, ignorableWhitespace, notationDecl, processingInstruction, resolveEntity, setDocumentLocator, skippedEntity, startDocument, startPrefixMapping, unparsedEntityDecl, warning`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### XMLNamespaceParser

          public XMLNamespaceParser(java.io.Reader xml)
                             throws org.xml.sax.SAXException,
                                    edu.ucsb.nceas.utilities.PropertyNotFoundException

      Constructor
      Parameters:
        `xml` - the xml object which will be parsed
      Throws:
        `org.xml.sax.SAXException`
        `edu.ucsb.nceas.utilities.PropertyNotFoundException`

  - ### Method Detail

    - #### parse

          public void parse()
                     throws org.xml.sax.SAXException,
                            java.io.IOException

      Parse the xml file
      Throws:
        `org.xml.sax.SAXException` - if some sax related exception happens
        `java.io.IOException` - if the schema content couldn't be found

    - #### startElement

          public void startElement(java.lang.String uri,
                                   java.lang.String localName,
                                   java.lang.String qName,
                                   org.xml.sax.Attributes atts)
                            throws org.xml.sax.SAXException

      SAX Handler that is called at the start of each XML element
      Specified by:
        `startElement` in interface `org.xml.sax.ContentHandler`
      Overrides:
        `startElement` in class `org.xml.sax.helpers.DefaultHandler`
      Throws:
        `org.xml.sax.SAXException`

    - #### getNamespace

          public java.lang.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 java.lang.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.

Copyright © 2020 Regents of the University of California. All Rights Reserved.