I recently saw an XML string containing <?var type="string" ?>. I would like to know if anyone has any idea what this means? It has something to do with PHP I imagine. Here is a contextual snippet.
<?xml version="1.0" encoding="UTF-8"?>
<node>
<?var type="string" ?>
<somenode>Value</somenode>
</node>
I can’t seem to search google for <?var so maybe you guys can help me out.
This is an XML processing instruction, and has nothing to do with PHP. (It isn’t legal PHP syntax anyway.) The XML declaration you see at the beginning of the document is a special kind of PI.
I can’t say much beyond that, though, as I’ve honestly never seen XML PIs used as XML PIs for anything in the wild, ever.
The<? ?>delimiters are usually recognized by developers as PHP delimiters (with a short opening delimiter) instead.Actually, as discussed in the comments, the full PHP delimiters
<?php ?>can be considered a kind of processing instruction, even though they’re used in a ton of other places besides XHTML/XML documents. One could even say that PHP was designed to be XHTML-compliant via processing instructions.In fact, the following XHTML markup, with a snippet of PHP, actually validates!
However, it does not validate with short opening tags, as an XML PI must begin with
<?followed by at least one name character. See the very first link to the spec for the PI grammar.