Parsed Character Data vs Markup in XML
In an Extensible Markup Language (XML) document, all text is fundamentally divided into either markup or character data. This article explores the core distinctions between raw markup—the structural code that defines the document’s framework—and Parsed Character Data (PCDATA), the actual textual content that the XML parser reads, analyzes, and prepares for application processing.
What is XML Markup?
Markup consists of the structural syntax that describes the document’s structure, semantics, and metadata. When an XML parser processes a file, it uses the markup to build a document tree (such as a Document Object Model, or DOM).
Markup includes: * Start and End Tags: Elements such
as <title> and </title>. *
Empty Element Tags: Elements without separate closing
tags, such as <br/>. * Attributes:
Key-value pairs inside tags, like id="123". *
Entity References: Predefined shortcuts like
< or &. *
Comments: Annotations intended for humans, enclosed in
<!-- -->. * Processing Instructions:
Application-specific instructions, such as
<?xml-stylesheet ... ?>. * Document Type
Declarations (DTD): Syntax defining document constraints, such
as <!DOCTYPE ...>.
What is Parsed Character Data (PCDATA)?
Parsed Character Data, commonly referred to as PCDATA, is the text found between start and end tags that is meant to be interpreted as content rather than structural code.
The term “parsed” signifies that the XML parser actively scans this
text to ensure it conforms to XML rules. During parsing: 1. The parser
searches for reserved characters, primarily the ampersand
(&) and the less-than symbol (<). 2. If
an ampersand is found, the parser attempts to resolve it as an entity
reference (for example, converting © to
©). 3. If a raw < character is found, the
parser expects it to be the start of a new markup tag; if it is not, an
error is generated.
Because PCDATA is scanned for markup delimiters, any literal
< or & symbols within the content must
be escaped using entities like < and
&, or wrapped in a
<![CDATA[ ... ]]> (Unparsed Character Data)
block.
Key Differences
| Feature | Raw Markup | Parsed Character Data (PCDATA) |
|---|---|---|
| Primary Purpose | Defines structure, tags, attributes, and document rules. | Represents the actual informational payload or text. |
| Parser Action | Read to construct the document tree and hierarchy. | Read and evaluated for entities to produce text nodes. |
| Reserved Characters | Uses <, >,
&, ", and ' as functional
syntax. |
Cannot contain raw < or
& characters; they must be escaped. |
| Visibility to End Users | Typically hidden; consumed by the application logic. | Typically visible as the final output or text content. |
Understanding this distinction ensures proper document structuring, prevents parsing errors caused by illegal characters, and facilitates correct data extraction in XML-driven applications.