Class XMLStreamSplitter
- java.lang.Object
-
- com.norconex.importer.handler.AbstractImporterHandler
-
- com.norconex.importer.handler.splitter.AbstractDocumentSplitter
-
- com.norconex.importer.handler.splitter.impl.XMLStreamSplitter
-
- All Implemented Interfaces:
IXMLConfigurable,IImporterHandler,IDocumentSplitter
public class XMLStreamSplitter extends AbstractDocumentSplitter implements IXMLConfigurable
Splits XML document on a specific element.
This class is suited for large XML documents. It will read the XML as a stream and split as it is read, preserving memory during parsing. For this reason, element matching is not as flexible as DOM-based XML parsers, such as
DOMSplitter, but is more efficient on large documents.Element matching
To identify the element to split on, you give the full path to it from the document root, where each element is separated by a forward slash. Let's take this XML as an example:
<animals> <species name="mouse"> <animal> <name>Itchy</name> <race>cartoon</race> </animal> </species> <species name="cat"> <animal> <name>Scratchy</name> <race>cartoon</race> </animal> </species> </animals>To split on
<animal>, you would use this path:/animals/species/animal
Should be used as a pre-parse handler.
Content-types
By default, this filter is restricted to (applies only to) documents matching the restrictions returned by
CommonRestrictions.xmlContentTypes(String). You can specify your own restrictions to further narrow, or loosen what documents this splitter applies to.XML configuration usage:
<handler class="com.norconex.importer.handler.splitter.impl.XMLStreamSplitter" path="(XML path)"> <!-- multiple "restrictTo" tags allowed (only one needs to match) --> <restrictTo> <fieldMatcher>(field-matching expression)</fieldMatcher> <valueMatcher>(value-matching expression)</valueMatcher> </restrictTo> </handler>XML usage example:
<handler class="XMLStreamSplitter" path="/animals/species/animal"/>The above example will create one document per animals, based on the sample XML given above.
- Since:
- 3.0.0
- Author:
- Pascal Essiembre
- See Also:
DOMSplitter
-
-
Constructor Summary
Constructors Constructor Description XMLStreamSplitter()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(Object other)StringgetPath()inthashCode()protected voidloadHandlerFromXML(XML xml)Loads configuration settings specific to the implementing class.protected voidsaveHandlerToXML(XML xml)Saves configuration settings specific to the implementing class.voidsetPath(String path)protected List<Doc>splitApplicableDocument(HandlerDoc doc, InputStream input, OutputStream output, ParseState parseState)StringtoString()-
Methods inherited from class com.norconex.importer.handler.splitter.AbstractDocumentSplitter
splitDocument
-
Methods inherited from class com.norconex.importer.handler.AbstractImporterHandler
addRestriction, addRestriction, addRestrictions, clearRestrictions, detectCharsetIfBlank, getRestrictions, isApplicable, loadFromXML, removeRestriction, removeRestriction, saveToXML
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.norconex.commons.lang.xml.IXMLConfigurable
loadFromXML, saveToXML
-
-
-
-
Method Detail
-
getPath
public String getPath()
-
setPath
public void setPath(String path)
-
splitApplicableDocument
protected List<Doc> splitApplicableDocument(HandlerDoc doc, InputStream input, OutputStream output, ParseState parseState) throws ImporterHandlerException
- Specified by:
splitApplicableDocumentin classAbstractDocumentSplitter- Throws:
ImporterHandlerException
-
loadHandlerFromXML
protected void loadHandlerFromXML(XML xml)
Description copied from class:AbstractImporterHandlerLoads configuration settings specific to the implementing class.- Specified by:
loadHandlerFromXMLin classAbstractImporterHandler- Parameters:
xml- XML configuration
-
saveHandlerToXML
protected void saveHandlerToXML(XML xml)
Description copied from class:AbstractImporterHandlerSaves configuration settings specific to the implementing class.- Specified by:
saveHandlerToXMLin classAbstractImporterHandler- Parameters:
xml- the XML
-
equals
public boolean equals(Object other)
- Overrides:
equalsin classAbstractImporterHandler
-
hashCode
public int hashCode()
- Overrides:
hashCodein classAbstractImporterHandler
-
toString
public String toString()
- Overrides:
toStringin classAbstractImporterHandler
-
-