Class XmlAttributes
Both directions are needed. Decoding lets the locator compare a user-supplied key such as
A&B against source text written as A&B. Encoding produces a replacement that
is correct for the quote character actually used at the target site, so a value containing a
quote can never break out of the attribute — which is the injection concern here, and the reason
escaping is driven by the observed source quote rather than by a fixed convention.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringDecodes the predefined XML entities and numeric character references.static StringEscapesvaluefor insertion betweenquotecharacters.static StringencodeText(String value) Escapesvaluefor use as element text rather than as an attribute value.
-
Method Details
-
encode
Escapesvaluefor insertion betweenquotecharacters.&and<are always escaped because they are never legal literally in an attribute value.>is escaped defensively. Only the delimiting quote is escaped, so an apostrophe inside a double-quoted attribute stays readable. -
encodeText
Escapesvaluefor use as element text rather than as an attribute value.Quotes are left alone: inside element content they carry no structural meaning, and escaping them would churn bytes for no reason.
&and<must be escaped because they are never legal literally;>is escaped defensively so that no accidental]]>sequence can form. -
decode
Decodes the predefined XML entities and numeric character references.Custom entities are not decoded: DTDs are disabled outright, so a document that defines one has already been rejected before this runs. Anything unrecognised is left verbatim rather than guessed at.
-