12

I know XML documents usually start with something like:

<?xml version="1.0" encoding="UTF-8"?>

My question is regarding the <? and ?> what do they mean on their own? As in what does:

<?Any old text?>

mean in XML

Thanks

More Than Five
  • 9,311
  • 20
  • 72
  • 121

2 Answers2

11

The <? sequence starts a so-called processing instruction. These are bits added for third-party software to process. Famously, <?php is technically a PI, but also things like XSLT stylesheet embedding:

<?xml-stylesheet href="classic.xsl" type="text/xml"?>
Boldewyn
  • 78,902
  • 44
  • 148
  • 207
8

It's a prolog – see 'The XML Prolog' in XML Syntax Rules at w3schools.com.

For more thorough definition see '2.8 Prolog and Document Type Declaration' in 'Extensible Markup Language (XML)' at W3C.

CiaPan
  • 9,188
  • 2
  • 19
  • 32
  • Can you have multiple prolog statements in an XML document, ever? For example, one to state the version and encoding and another to just pass some information to the engine? – More Than Five Aug 24 '16 at 09:24
  • 1
    @MoreThanFive Yes & no. Yes, you can have multiple Processing instructions (`...?>`), but No, you can have only one Prolog (``). The ['2.1 Well-Formed XML Documents'](http://www.w3.org/TR/REC-xml/#sec-well-formed) section of the w3c document describes a well-formed XML document as having exactly one prolog, and the prolog definition says it can contain at most one XMLDecl, which is ``. – CiaPan Aug 24 '16 at 09:33
  • 1
    @MoreThanFive (contd.) ...and the ['2.6 Processing Instructions'](http://www.w3.org/TR/REC-xml/#sec-pi) definition explicitly excludes `xml` from allowed `name`s of PI. – CiaPan Aug 24 '16 at 09:40