|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2005-08-29 17:28 UTC] vrana@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Fri Oct 24 16:00:02 2025 UTC |
Description: ------------ xml_set_processing_instruction_handler manual page says: --- BEGIN QUOTE A processing instruction has the following format: <? target data?> --- END QUOTE The truth is: <?target data?> There cannot be any space between '<?' and target. This can be verified: 1. According to the XML 1.0 Specification, and 2. According to how xml_set_processing_instruction_handler() behaves --- BEGIN QUOTED MATERIAL 2.6 Processing Instructions [Definition: Processing instructions (PIs) allow documents to contain instructions for applications.] Processing Instructions [16] PI ::= '<?' PITarget (S (Char* - (Char* '?>' Char*)))? '?>' [17] PITarget ::= Name - (('X' | 'x') ('M' | 'm') ('L' | 'l')) REFERENCE: XML 1.0 (Third Edition): http://www.w3.org/TR/REC-xml/#sec-pi Reproduce code: --------------- --- test.php <?php $q = '?'; $validPI = <<< EOD <{$q}xml version="1.0"{$q}> <test> PHP 5.0.2 <{$q}pi DATA {$q}> </test> EOD; $invalidPI = <<< EOD <{$q}xml version="1.0"{$q}> <test> PHP 5.0.2 <{$q} pi DATA {$q}> </test> EOD; $parser = xml_parser_create(); xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0); // this doesn't do anything: xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0); xml_set_element_handler($parser, "start_element", "stop_element"); xml_set_character_data_handler($parser, "char_data"); xml_set_processing_instruction_handler( $parser, "_handlePI"); echo "--- VALID PI in document:\n$validPI\n"; echo "--- Result of parsing:\n"; xml_parse( $parser, $validPI ); echo "\n"; echo "--- INVALID PI in document:\n$invalidPI\n"; echo "--- Result of parsing:\n"; xml_parse( $parser, $invalidPI ); function _handlePI($parser, $target, $data) { echo(">>>".$data."<<<"); } function start_element($parser, $data, $attribs) { echo $data; } function stop_element($parser, $data ) { echo $data; } function char_data($parser, $data ) { echo $data; } ?> Actual result: -------------- [greg@p3 test]$ php test.php --- VALID PI in document: <?xml version="1.0"?> <test> PHP 5.0.2 <?pi DATA ?> </test> --- Result of parsing: test PHP 5.0.2 >>>DATA <<< test --- INVALID PI in document: <?xml version="1.0"?> <test> PHP 5.0.2 <? pi DATA ?> </test> --- Result of parsing: [greg@p3 test]$