Enum QuoteStyle

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Comparable<QuoteStyle>

    public enum QuoteStyle
    extends java.lang.Enum<QuoteStyle>
    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:
    Attribute, Element.attribute(String, String, QuoteStyle), DomTripConfig.withDefaultQuoteStyle(QuoteStyle)
    • Enum Constant Summary

      Enum Constants 
      Enum Constant Description
      DOUBLE
      Double quote character (") for attribute values
      SINGLE
      Single quote character (') for attribute values
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods 
      Modifier and Type Method Description
      char character()
      Gets the quote character for this style.
      static QuoteStyle fromChar​(char c)
      Returns the QuoteStyle corresponding to the given character.
      char getCharacter()
      Deprecated.
      Use character() instead.
      java.lang.String toString()
      Returns the quote character as a string.
      static QuoteStyle valueOf​(java.lang.String name)
      Returns 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.
      • Methods inherited from class java.lang.Enum

        clone, compareTo, equals, finalize, getDeclaringClass, hashCode, name, ordinal, valueOf
      • Methods inherited from class java.lang.Object

        getClass, notify, notifyAll, wait, wait, wait
    • Enum Constant Detail

      • DOUBLE

        public static final QuoteStyle DOUBLE
        Double quote character (") for attribute values
      • SINGLE

        public static final QuoteStyle SINGLE
        Single quote character (') for attribute values
    • Method Detail

      • values

        public static QuoteStyle[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (QuoteStyle c : QuoteStyle.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static QuoteStyle valueOf​(java.lang.String name)
        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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null
      • character

        public char character()
        Gets the quote character for this style.
        Returns:
        the quote character (either '"' or '\'')
      • getCharacter

        @Deprecated
        public char getCharacter()
        Deprecated.
        Use character() instead.
        Gets the quote character for this style.
        Returns:
        the quote character
      • fromChar

        public static QuoteStyle fromChar​(char c)
                                   throws DomTripException
        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

        public java.lang.String toString()
        Returns the quote character as a string.
        Overrides:
        toString in class java.lang.Enum<QuoteStyle>
        Returns:
        the quote character as a single-character string