Class XMLUtils
- Version:
- 2.0, 24 March 2004
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic StringReplaces characters which are invalid in element values, by the corresponding entity in a givenString.static StringescapeAttr(String s) Replace characters which are invalid in attribute values, by the corresponding entity in a givenString.static StringtoElementName(String name) Return a valid element name from the given string.
-
Constructor Details
-
XMLUtils
private XMLUtils()Prevents creation of instances.
-
-
Method Details
-
escape
Replaces characters which are invalid in element values, by the corresponding entity in a givenString.these characters are:
- '&' by the ampersand entity "&"
- '<' by the entity "<"
Empty strings or
nullreturn respectively "" andnull.Note: this function assumes that there are no entities in the given String. If there are existing entities, then the ampersand character will be escaped by the ampersand entity.
This method does not replaces " (by ") which is an invalid character in attribute values.
- Parameters:
s- The String to be parsed- Returns:
- a valid string or empty if s is
nullor empty. - See Also:
-
escapeAttr
Replace characters which are invalid in attribute values, by the corresponding entity in a givenString.these characters are:
- '&' by the ampersand entity "&"
- '<' by the entity "<"
- ''' by the entity "'"
- '"' by the entity """
Empty strings or
nullreturn respectively "" andnull.Note: this function assumes that there are no entities in the given String. If there are existing entities, then the ampersand character will be escaped by the ampersand entity.
- Parameters:
s- The String to be parsed- Returns:
- a valid string or empty if s is
nullor empty.
-
toElementName
Return a valid element name from the given string.Letters are put to lower case and other characters are replaced by hyphens. If the first character is not a letter it is replaced by 'x'.
- Parameters:
name- The candidate element name- Returns:
- A valid element name
-