Skip to main content

XML error · syntax

Processing instruction not terminated

A processing instruction was opened with <? and never closed with ?>. Everything after it is consumed as instruction data until the file runs out.

ParsePI: PI target never end ... (line 2)

What it means

A processing instruction carries a target and data to an application — <?xml-stylesheet …?> is the one most people meet. It ends at ?>, and until the parser sees that it treats every following byte as part of the instruction.

The trailing ellipsis in libxml2's message is not truncation on our side; the parser prints it because the instruction it was reading never came to an end.

What usually causes it

  • A stylesheet instruction closed with > rather than ?>.
  • A templating language whose own <? … ?> delimiters were emitted into the output instead of being executed.
  • PHP short tags landing in an XML response.
  • Hand-editing a processing instruction and removing the question mark.

How to fix it

  • Close it with ?> — the question mark is part of the terminator, not decoration.
  • Check the document for stray <? sequences that were never meant to be instructions.
  • If a template engine shares the delimiter, escape it or switch the engine's delimiters.

The same error elsewhere

Different parsers, same defect. If you arrived with one of these messages, you are in the right place.

  • Xerces (Java)

    The processing instruction must end with "?>".
  • expat (Python)

    unclosed token: line 2, column 6
  • .NET System.Xml

    Unexpected end of file has occurred.

Before and after

Both snippets are re-checked by the test suite against the real parser: the first is confirmed to produce the exact error above, the second to parse cleanly.

Fails
<?xml version="1.0"?>
<root><?target data</root>
Parses
<?xml version="1.0"?>
<root><?target data?></root>

Where this bites most

Get started

Bring order to the XML your team can't afford to ignore.

Create a free account and get a private workspace to search, validate, diff, and monitor your XML feeds, sitemaps, schemas, and vendor integrations.