Skip to main content

DomSplitter

Splits HTML, XHTML, or XML document on elements matching a given selector.

Notes

This option builds a full DOM tree from the document content in memory. For large files, be cautious—this can use a lot of memory. For better performance with big files, consider a streaming approach like (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.

Content-types

By default, this filter applies only to documents with content types specified by the CommonRestrictions.domContentTypes(String) method. You can also define your own content types if they represent files containing HTML or XML-like markup tags.

Common content-types:

  • application/atom+xml
  • application/mathml+xml
  • application/rss+xml
  • application/vnd.wap.xhtml+xml
  • application/x-asp
  • application/xhtml+xml
  • application/xml
  • application/xslt+xml
  • image/svg+xml
  • text/html
  • text/xml

Parser Handler Compatibility

This functionality can be applied as either a pre-parse or post-parse handler.

Examples

The following example splits contant found in an HTML document, each one being stored within a div with a class named "contact".

handler:
class: DomSplitter
selector: div.contact

content Type

The following example splits content from a field named embedded_file, but only when the content type is text/html. It targets HTML elements matching the div.contact selector within that field

handler:
class: DomSplitter
selector: div.contact
parser: HTML
contentTypeMatcher:
method: BASIC
pattern: text/html
fieldMatcher:
method: BASIC
pattern: embedded_file

Usage

Full configuration skeleton, with every option and its default
class: DomSplitter
contentTypeMatcher:
ignoreCase: false
ignoreDiacritic: false
matchEmpty: false
method: BASIC
negateMatches: false
partial: false
pattern: string
replaceAll: false
trim: false
discardOriginal: false
fieldMatcher:
ignoreCase: false
ignoreDiacritic: false
matchEmpty: false
method: BASIC
negateMatches: false
partial: false
pattern: string
replaceAll: false
trim: false
label: string
parser: string
selector: string
sourceCharset: string

Properties

PropertyTypeRequiredDefault
contentTypeMatcherTextMatcherNoTextMatcher
discardOriginalbooleanNofalse
fieldMatcherTextMatcherNoTextMatcher
labelstringNo-
parserstringNohtml
selectorstringNo-
sourceCharsetstringNo-

Property Details

contentTypeMatcher

By default, this filter applies only to documents with content types specified by the CommonRestrictions.domContentTypes(String) method. You can also define your own content types if they represent files containing HTML or XML-like markup tags.

Common content-types:

  • application/atom+xml
  • application/mathml+xml
  • application/rss+xml
  • application/vnd.wap.xhtml+xml
  • application/x-asp
  • application/xhtml+xml
  • application/xml
  • application/xslt+xml
  • image/svg+xml
  • text/html
  • text/xml

discardOriginal

Discard the original document after the split is performed.

fieldMatcher

Matches document fields based on specified patterns and methods

label

An optional, user-supplied label for this step in the importer pipeline. It has no effect on processing — it exists purely to help identify this step, for example in large configurations or in the visual configurator.

parser

Defines using XML or HTML parser.

selector

XPath expression for splitting nodes.

sourceCharset

Sets the character encoding of the source document to ensure proper reading and processing.