Package com.itextpdf.text.xml
Class XMLUtil
java.lang.Object
com.itextpdf.text.xml.XMLUtil
Contains utility methods for XML.
- Since:
- 5.0.6
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic String
Escapes a string with the appropriated XML codes.static int
findInArray
(char needle, char[] haystack, int start) Looks for a character in a character array, starting from a certain positionstatic String
getEncodingName
(byte[] b4) Returns the IANA encoding name that is auto-detected from the bytes specified, with the endian-ness of that encoding where appropriate.static boolean
isValidCharacterValue
(int c) Checks if a character value should be escaped/unescaped.static boolean
Checks if a character value should be escaped/unescaped.static int
Unescapes 'lt', 'gt', 'apos', 'quote' and 'amp' to the corresponding character values.static String
Unescapes a String, replacing invalid input: '&#'nn;, <, >, &, ", and invalid input: '&apos' to the corresponding characters.
-
Constructor Details
-
XMLUtil
public XMLUtil()
-
-
Method Details
-
escapeXML
Escapes a string with the appropriated XML codes.- Parameters:
s
- the string to be escapedonlyASCII
- codes above 127 will always be escaped with &#nn; iftrue
- Returns:
- the escaped string
- Since:
- 5.0.6
-
unescapeXML
Unescapes a String, replacing invalid input: '&#'nn;, <, >, &, ", and invalid input: '&apos' to the corresponding characters.- Parameters:
s
- a String with entities- Returns:
- the unescaped string
-
unescape
Unescapes 'lt', 'gt', 'apos', 'quote' and 'amp' to the corresponding character values.- Parameters:
s
- a string representing a character- Returns:
- a character value
-
isValidCharacterValue
Checks if a character value should be escaped/unescaped.- Parameters:
s
- the String representation of an integer- Returns:
- true if it's OK to escape or unescape this value
-
isValidCharacterValue
public static boolean isValidCharacterValue(int c) Checks if a character value should be escaped/unescaped.- Parameters:
c
- a character value- Returns:
- true if it's OK to escape or unescape this value
-
findInArray
public static int findInArray(char needle, char[] haystack, int start) Looks for a character in a character array, starting from a certain position- Parameters:
needle
- the character you're looking forhaystack
- the character arraystart
- the start position- Returns:
- the position where the character was found, or -1 if it wasn't found.
-
getEncodingName
Returns the IANA encoding name that is auto-detected from the bytes specified, with the endian-ness of that encoding where appropriate. (method found in org.apache.xerces.impl.XMLEntityManager, originally published by the Apache Software Foundation under the Apache Software License; now being used in iText under the MPL)- Parameters:
b4
- The first four bytes of the input.- Returns:
- an IANA-encoding string
- Since:
- 5.0.6
-