Normalized Value vs Raw Text in XML Infoset

In the XML Information Set (Infoset) and related XML Schema specifications, the difference between raw text and a normalized value lies in the level of processing applied to the character data. Raw text represents the exact, literal sequence of characters as written in the source XML document, preserving all formatting and whitespace. In contrast, the normalized value is the refined string produced after an XML parser or schema processor applies specific normalization algorithms—such as whitespace collapsing or data-type formatting rules—to generate a clean, canonical representation of the data.

Understanding Raw Text

Raw text, often referred to as the lexical representation or unnormalized character data, consists of the original character information items generated during the initial parsing phase of an XML document.

Key characteristics of raw text include: * Literal Preservation: It retains all source formatting, including leading, trailing, and contiguous internal whitespace (such as spaces, tabs, and carriage returns). * Pre-Validation State: It captures text before any XML Schema Definition (XSD) rules or datatype-specific constraints are evaluated. * Direct Mapping: It reflects the exact characters between an element’s opening and closing tags, resolving only basic XML entity references (such as & or <).

Understanding Normalized Value

A normalized value represents the data after it has undergone schema processing, attribute-value normalization, or type-based transformation. In the context of the Post-Schema-Validation Infoset (PSVI), this is typically exposed as the [schema normalized value] property.

Key characteristics of normalized value include: * Whitespace Facet Application: Normalization modifies whitespace according to schema rules using three primary modes: * Preserve: No whitespace is altered. * Replace: All tabs, line feeds, and carriage returns are replaced with single space characters. * Collapse: After replacement, contiguous spaces are collapsed into a single space, and all leading and trailing whitespace is stripped. * Datatype Canonicalization: For typed data (such as integers, booleans, or dates), normalization interprets the lexical representation to standard forms (for example, converting the raw text " 0042 " to the normalized integer value "42", or " true " to "true"). * Semantic Consistency: It ensures that syntactically different text representations that carry the same meaning evaluate identically in downstream applications.

Key Differences at a Glance

Feature Raw Text (Lexical Representation) Normalized Value (PSVI)
Processing Stage Syntactic XML parsing (Infoset creation) Post-Schema-Validation (PSVI)
Whitespace Handling Fully preserved as written Replaced, collapsed, or trimmed per datatype rules
Leading/Trailing Spaces Maintained Removed for most atomic schema types
Data Comparison Compared character-by-character literally Compared by resolved semantic value

Example Comparison

Consider the following XML element representing a numeric identifier:

<productID>
    00149
</productID>

Distinguishing between raw text and normalized values ensures that applications can display text precisely as authored when necessary, while also performing accurate, standardized comparisons and queries during data validation.