Enum QuoteStyle
- All Implemented Interfaces:
Serializable, Comparable<QuoteStyle>, java.lang.constant.Constable
Enumeration for XML attribute quote styles, supporting both single and double quotes.
XML attributes can be quoted with either single quotes (') or double quotes ("). DomTrip preserves the original quote style during round-trip processing and allows explicit control over quote style when creating new attributes.
Quote Style Preservation:
When parsing XML, DomTrip automatically detects and preserves the original quote style for each attribute. This ensures that the serialized XML maintains the exact same formatting as the input.
Usage Examples:
// Set attribute with specific quote style
element.attribute("class", "important", QuoteStyle.SINGLE);
// Results in: class='important'
element.attribute("id", "main", QuoteStyle.DOUBLE);
// Results in: id="main"
// Get quote style from character
QuoteStyle style = QuoteStyle.fromChar('"'); // DOUBLE
QuoteStyle style2 = QuoteStyle.fromChar('\''); // SINGLE
// Use in configuration
DomTripConfig config = DomTripConfig.defaults()
.withQuoteStyle(QuoteStyle.SINGLE);
XML Specification Compliance:
Both quote styles are valid according to the XML specification. The choice between them is often a matter of style preference or necessity when the attribute value contains one type of quote character.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum Constants -
Method Summary
Modifier and TypeMethodDescriptioncharGets the quote character for this style.static QuoteStylefromChar(char c) Returns the QuoteStyle corresponding to the given character.charDeprecated.toString()Returns the quote character as a string.static QuoteStyleReturns the enum constant of this type with the specified name.static QuoteStyle[]values()Returns an array containing the constants of this enum type, in the order they are declared.
-
Enum Constant Details
-
DOUBLE
Double quote character (") for attribute values -
SINGLE
Single quote character (') for attribute values
-
-
Method Details
-
values
Returns an array containing the constants of this enum type, in the order they are declared.- Returns:
- an array containing the constants of this enum type, in the order they are declared
-
valueOf
Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)- Parameters:
name- the name of the enum constant to be returned.- Returns:
- the enum constant with the specified name
- Throws:
IllegalArgumentException- if this enum type has no constant with the specified nameNullPointerException- if the argument is null
-
character
public char character()Gets the quote character for this style.- Returns:
- the quote character (either '"' or '\'')
-
getCharacter
Deprecated.Usecharacter()instead.Gets the quote character for this style.- Returns:
- the quote character
-
fromChar
Returns the QuoteStyle corresponding to the given character.This method is useful when parsing XML attributes to determine the original quote style used.
- Parameters:
c- the quote character to convert- Returns:
- the corresponding QuoteStyle
- Throws:
DomTripException- if the character is not a valid quote character
-
toString
Returns the quote character as a string.- Overrides:
toStringin classEnum<QuoteStyle>- Returns:
- the quote character as a single-character string
-
character()instead.