Package org.evoludo.util
Class XMLCoder
Object
XMLCoder
Encode and decode XML strings.
- Author:
- Christoph Hauert
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivateXMLCoder()Suppresses default constructor, ensuring non-instantiability. -
Method Summary
Modifier and TypeMethodDescriptionstatic StringDecode XML string.static StringEncode string as XML.private static voidinit()Initialize lookup tables for encoding and decoding XML strings.static booleanisStrict()Check if encoding/decoding is strictly XML compliant.static voidsetStrict(boolean strict) Set the encoding/decoding mode tostrict.
-
Field Details
-
XMLDecode
Lookup table for decoding XML strings. -
XMLEncode
Lookup table for encoding XML strings. -
strict
private static boolean stricttrueto strictly adhering to XML standard. Iffalsesome additional characters are encoded/decoded that are invalid in XML (or XHTML) but acceptable in ePubs.
-
-
Constructor Details
-
XMLCoder
private XMLCoder()Suppresses default constructor, ensuring non-instantiability.
-
-
Method Details
-
setStrict
public static void setStrict(boolean strict) Set the encoding/decoding mode tostrict. The encoding/decoding strictly adheres to XML standards iftrue. If the mode changed the (static) lookup tables are re-initialized.- Parameters:
strict- encoding/decoding mode- See Also:
-
isStrict
public static boolean isStrict()Check if encoding/decoding is strictly XML compliant.- Returns:
trueif strictly compliant
-
encode
Encode string as XML. Ifstrict==falsesome additional characters are encoded that still validate in ePub's.Note: XHTML is very fussy about characters in argument to innerHTML. It does not seem to accept any kind of special character even when properly encoded. For example, the properly encoded
'√'(√) or√both result in an error (even though the latter is perfectly fine in XHTML documents).- Parameters:
string- the string to encode in XML- Returns:
- the encoded string
-
decode
Decode XML string. Ifstrict==falsesome additional characters are decoded that still validate in ePub's.- Parameters:
string- the XML string to decode- Returns:
- the decoded string
-
init
private static void init()Initialize lookup tables for encoding and decoding XML strings.
-