Package org.evoludo.util
Class XMLCoder
Object
XMLCoder
Encode and decode XML strings.
- Author:
- Christoph Hauert
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprivate
XMLCoder()
Suppresses default constructor, ensuring non-instantiability. -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Decode XML string.static String
Encode string as XML.private static void
init()
Initialize lookup tables for encoding and decoding XML strings.static boolean
isStrict()
Check if encoding/decoding is strictly XML compliant.static void
setStrict
(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 stricttrue
to strictly adhering to XML standard. Iffalse
some 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:
true
if strictly compliant
-
encode
Encode string as XML. Ifstrict==false
some 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==false
some 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.
-