Package edu.ucsb.nceas.metacat.service
Class XMLNamespaceParser
java.lang.Object
org.xml.sax.helpers.DefaultHandler
edu.ucsb.nceas.metacat.service.XMLNamespaceParser
- All Implemented Interfaces:
ContentHandler
,DTDHandler
,EntityResolver
,ErrorHandler
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
-
Method Summary
Modifier and TypeMethodDescriptionGet the namespace of the document (root element).Get the value of noNamespaceSchemaLocation of the document (root element).void
parse()
Parse the xml filevoid
startElement
(String uri, String localName, String qName, Attributes atts) SAX Handler that is called at the start of each XML elementMethods 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
Methods inherited from interface org.xml.sax.ContentHandler
declaration
-
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
Parse the xml file- Throws:
SAXException
- if some sax related exception happensIOException
- 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 interfaceContentHandler
- Overrides:
startElement
in classDefaultHandler
- Throws:
SAXException
-
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
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.
-