public abstract class SemanticXmlReader extends java.lang.Object implements FormatReader<OwlThing>
Class for creating semantic ontology objects from XML files. Because both XML schemas and ontologies can become very complex, and the mapping between the two is not straightforward, this class is abstract, and uses reflection to parse individual XML elements.
Subclasses that extend this class for specific XML schemas should implement
methods in the form convert_tagName
, where tagName is
the element tag name for elements that should be converted to Owl objects.
The method takes two arguments; the first is the
org.w3c.dom.Element
object that contains the XML data, and the
second is a java.util.List
of OwlThing objects. The method
should return the top-level OwlThing created (if any). Any new objects
created should also be stored in the list. So for instance, a method that
parses elements with a tagName of Foo should be
OwlThing convert_Foo(Element elem, List<OwlThing> list)
.
The tagName is case-sensitive and should match the tagName in the XML
exactly.
Constructor and Description |
---|
SemanticXmlReader()
Create a new Semantic XML reader without specifying a file or directory.
|
SemanticXmlReader(java.io.File file)
Create a new Semantic XML reader from a file or directory.
|
SemanticXmlReader(java.net.URL xmlUrl)
Create a new reader from a URL.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canRead()
Return whether the reader can read data
|
void |
close()
Close the reader, clearing any references to connections
|
protected java.lang.String |
getBaseTag(org.w3c.dom.Element elem)
Get the base tag - the tag without the prefix - for an element.
|
java.lang.String |
getFilters()
Get the filters for this reader.
|
java.lang.String |
getSource()
Get the source of the data.
|
boolean |
hasMoreData()
Return whether the reader has more data
|
protected void |
loadDatatypeProps(OwlThing thing,
org.w3c.dom.Element elem)
Load data properties when the element tag name matches a datatype
property from the ontology.
|
java.util.List<OwlThing> |
readData()
Read the XML data, parsing it into a list of OWL objects.
|
protected OwlThing |
readElement(org.w3c.dom.Element elem,
java.util.List<OwlThing> list)
Read an element, converting it or its child elements to OwlThings.
|
void |
setFilters(java.lang.String filters)
Set any filters for processing.
|
void |
setSource(java.lang.String source)
Set the source.
|
public SemanticXmlReader()
public SemanticXmlReader(java.io.File file)
file
- the file to readpublic SemanticXmlReader(java.net.URL xmlUrl)
xmlUrl
- the URL to read data frompublic boolean canRead()
canRead
in interface FormatReader<OwlThing>
public void close()
close
in interface FormatReader<OwlThing>
protected java.lang.String getBaseTag(org.w3c.dom.Element elem)
elem
- public java.lang.String getFilters()
getFilters
in interface FormatReader<OwlThing>
public java.lang.String getSource()
getSource
in interface FormatReader<OwlThing>
public boolean hasMoreData()
hasMoreData
in interface FormatReader<OwlThing>
protected void loadDatatypeProps(OwlThing thing, org.w3c.dom.Element elem)
thing
- the OwlThing to add properties toelem
- the element containing the child elementspublic java.util.List<OwlThing> readData()
readData
in interface FormatReader<OwlThing>
protected OwlThing readElement(org.w3c.dom.Element elem, java.util.List<OwlThing> list)
Read an element, converting it or its child elements to OwlThings. This
method first determines if a method called convert_tagName
exists, where tagName is the tagName of the XML element (removing any
prefix delineated by a colon). If the convert_tagName
method exists, it is invoked with the element and list. Otherwise, this
method reads all child elements, invoking this method recursively.
Any new objects are stored in the list of OwlThings provided.
elem
- the element to readlist
- the list of elements. The contents of the list are modified
by this methodpublic void setFilters(java.lang.String filters)
setFilters
in interface FormatReader<OwlThing>
filters
- the set of filters.public void setSource(java.lang.String source)
setSource
in interface FormatReader<OwlThing>
source
- the source