In an XML string, but what does this mean? I recently saw an XML string containing . I would li...">

Saw <? Var type = "string"?> In an XML string, but what does this mean?

I recently saw an XML string containing <?var type="string" ?> . I would like to know if anyone knows what this means? It has something to do with PHP. Here is the context fragment.

 <?xml version="1.0" encoding="UTF-8"?> <node> <?var type="string" ?> <somenode>Value</somenode> </node> 

I can't find google for <?var , so maybe you guys can help me.

+8
xml
source share
2 answers

This is an XML processing instruction and has nothing to do with PHP. (This is not legal PHP syntax anyway.) The XML declaration that you see at the beginning of the document is a special kind of PI.

I can't say much about this, though, since I honestly have never seen XML PIs used as XML PIs for anything in the wild, never. Separators <? ?> <? ?> are usually recognized by developers as PHP delimiters (with a short opening delimiter).

Actually, as discussed in the comments, full PHP <?php ?> can be considered as a kind of processing instruction, even if they are used in tons of places other than XHTML / XML documents. You could even say that PHP was designed to be XHTML-compliant with processing instructions.

In fact, the following XHTML markup with a PHP snippet actually checks !

 <?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title></title> </head> <body> <p><?php echo 'Hello world!'; ?></p> </body> </html> 

However, it does not validate short-opening tags, since the XML PI must begin with <? followed by at least one character in the name. See the First Specification Link for PI Grammar.

+7
source share

This is what is in the zend 5-5 study guide. Question: "What is wrong with this XML document?" and the answer is "nothing"

I suppose the part is for PHP code, but re-declaring the xml seems weird, so I put that xml in a file and opened it in my browser, and the error:

This page contains an error on line 7 in column 6: XML declaration allowed only at the start of the document . Below is a page rendering before the first error.

Value

So why does the research guide say that nothing happened with xml ??

 <?xml version="1.0" encoding="UTF-8"?> <node> <?var type="string" ?> <leaf>Value</leaf> </node> <?xml version="1.0" encoding="UTF-8"?> <node> <?var type="string" ?> <leaf>Value</leaf> </node> 
+4
source share

All Articles