Class DomTripConfig
DomTripConfig provides comprehensive control over how XML documents are parsed, processed, and serialized. It supports various formatting styles from strict preservation to pretty printing, allowing users to choose the appropriate balance between formatting preservation and readability.
Configuration Categories:
- Preservation Settings - Control what formatting elements to preserve
- Output Formatting - Configure pretty printing and indentation
- Parsing Behavior - Control validation and error handling
- Default Values - Set defaults for encoding, quotes, etc.
Common Usage Patterns:
// Default preservation
DomTripConfig defaults = DomTripConfig.defaults();
// Pretty printing for readable output
DomTripConfig pretty = DomTripConfig.prettyPrint()
.withIndentString(" ")
.withDefaultQuoteStyle(QuoteStyle.DOUBLE);
// Minimal output for size optimization
DomTripConfig minimal = DomTripConfig.minimal()
.withCommentPreservation(false);
// Custom configuration
DomTripConfig custom = DomTripConfig.defaults()
.withDefaultQuoteStyle(QuoteStyle.SINGLE)
.withEmptyElementStyle(EmptyElementStyle.SELF_CLOSING_SPACED);
Builder Pattern:
DomTripConfig uses a fluent builder pattern for easy configuration:
DomTripConfig config = DomTripConfig.defaults()
.withCommentPreservation(true)
.withPrettyPrint(false)
.withIndentString(" ")
.withDefaultQuoteStyle(QuoteStyle.SINGLE)
.withEmptyElementStyle(EmptyElementStyle.EXPANDED);
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic DomTripConfigdefaults()Creates a default configuration with all preservation features enabled.booleanbooleanbooleanbooleanbooleanstatic DomTripConfigminimal()Creates a minimal configuration for compact output.static DomTripConfigCreates a configuration optimized for pretty printing.static DomTripConfigraw()Creates a raw configuration for completely unformatted output.withAutoDetectedEmptyElementStyle(Document document) Automatically detects and configures the empty element style based on existing empty elements in the provided document.withCommentPreservation(boolean preserve) withDefaultQuoteStyle(QuoteStyle quoteStyle) withEmptyElementStyle(EmptyElementStyle emptyElementStyle) withIgnoreInvalidEncoding(boolean ignoreInvalidEncoding) withIndentString(String indentString) withLineEnding(String lineEnding) withPrettyPrint(boolean prettyPrint) withProcessingInstructionPreservation(boolean preserve) withXmlDeclaration(boolean include)
-
Method Details
-
defaults
Creates a default configuration with all preservation features enabled. -
prettyPrint
Creates a configuration optimized for pretty printing. -
minimal
Creates a minimal configuration for compact output. -
raw
Creates a raw configuration for completely unformatted output.Raw mode produces XML with no line breaks or indentation whatsoever, resulting in a single continuous line of XML. This is useful for minimizing file size or when formatting is not desired.
-
withCommentPreservation
-
withProcessingInstructionPreservation
-
withDefaultQuoteStyle
-
withPrettyPrint
-
withIndentString
-
withLineEnding
-
withXmlDeclaration
-
withEmptyElementStyle
-
withIgnoreInvalidEncoding
-
withAutoDetectedEmptyElementStyle
Automatically detects and configures the empty element style based on existing empty elements in the provided document.This method analyzes all empty elements in the document to determine the predominant style and configures this DomTripConfig to use that style. If no empty elements are found, the current style is preserved.
- Parameters:
document- the document to analyze for empty element styles- Returns:
- this DomTripConfig for method chaining
-
isPreserveComments
public boolean isPreserveComments() -
isPreserveProcessingInstructions
public boolean isPreserveProcessingInstructions() -
defaultQuoteStyle
-
emptyElementStyle
-
isPrettyPrint
public boolean isPrettyPrint() -
indentString
-
lineEnding
-
isOmitXmlDeclaration
public boolean isOmitXmlDeclaration() -
isIgnoreInvalidEncoding
public boolean isIgnoreInvalidEncoding()
-