Class DomSplitterConfig
- All Implemented Interfaces:
Labelable
Splits HTML, XHTML, or XML document on elements matching a given selector.
This class constructs a DOM tree from the document content. That DOM tree
is loaded entirely into memory. Use this splitter with caution if you know
you'll need to parse huge files. It may be preferable to use a stream-based
approach if this is a concern (e.g., XmlStreamSplitter).
The jsoup parser library is used to load a document content into a DOM tree. Elements are referenced using a CSS or JQuery-like syntax.
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.domContentTypes(String).
You can specify your own content types if you know they represent a file
with HTML or XML-like markup tags.
Since 2.5.0, when used as a pre-parse handler,
this class attempts to detect the content character
encoding unless the character encoding
was specified using setSourceCharset(Charset). Since document
parsing converts content to UTF-8, UTF-8 is always assumed when
used as a post-parse handler.
Since 2.8.0, you can specify which parser to use when reading documents. The default is "html" and will normalize the content as HTML. This is generally a desired behavior, but this can sometimes have your selector fail. If you encounter this problem, try switching to "xml" parser, which does not attempt normalization on the content. The drawback with "xml" is you may not get all HTML-specific selector options to work. If you know you are dealing with XML to begin with, specifying "xml" should be a good option.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanbooleanThe matcher of content types to apply splitting on.Matcher of one or more fields to use as the source of content to split into new documents, instead of the original document content.The type of parser to use when creating the DOM-tree.The CSS-like selector (see class documentation) identifying which elements to split.The presumed source character set.inthashCode()setContentTypeMatcher(TextMatcher contentTypeMatcher) The matcher of content types to apply splitting on.setFieldMatcher(TextMatcher fieldMatcher) The type of parser to use when creating the DOM-tree.setSelector(String selector) The CSS-like selector (see class documentation) identifying which elements to split.setSourceCharset(Charset sourceCharset) The presumed source character set.toString()Methods inherited from class com.norconex.importer.handler.splitter.BaseDocumentSplitterConfig
isDiscardOriginal, setDiscardOriginalMethods inherited from class com.norconex.importer.handler.BaseLabelableConfig
getLabel, setLabel
-
Constructor Details
-
DomSplitterConfig
public DomSplitterConfig()
-
-
Method Details
-
setFieldMatcher
-
setContentTypeMatcher
The matcher of content types to apply splitting on. No attempt to split documents of any other content types will be made. Default isCommonMatchers.DOM_CONTENT_TYPES.- Parameters:
contentTypeMatcher- content type matcher- Returns:
- this
-
getSelector
The CSS-like selector (see class documentation) identifying which elements to split.- Returns:
- the selector
-
getSourceCharset
The presumed source character set.- Returns:
- character set of the source to be transformed
-
getParser
The type of parser to use when creating the DOM-tree. Default ishtml.- Returns:
htmlorxml.
-
getFieldMatcher
Matcher of one or more fields to use as the source of content to split into new documents, instead of the original document content.- Returns:
- field matcher
-
getContentTypeMatcher
The matcher of content types to apply splitting on. No attempt to split documents of any other content types will be made. Default isCommonMatchers.DOM_CONTENT_TYPES.- Returns:
- content type matcher
-
setSelector
The CSS-like selector (see class documentation) identifying which elements to split.- Parameters:
selector- the selector- Returns:
this.
-
setSourceCharset
The presumed source character set.- Parameters:
sourceCharset- character set of the source to be transformed- Returns:
this.
-
setParser
The type of parser to use when creating the DOM-tree. Default ishtml.- Parameters:
parser-htmlorxml.- Returns:
this.
-
equals
- Overrides:
equalsin classBaseDocumentSplitterConfig
-
canEqual
- Overrides:
canEqualin classBaseDocumentSplitterConfig
-
hashCode
public int hashCode()- Overrides:
hashCodein classBaseDocumentSplitterConfig
-
toString
- Overrides:
toStringin classBaseDocumentSplitterConfig
-