note 101229 deleted from function.xml-set-end-namespace-decl-handler by danbrown

From: Date: Fri, 03 Dec 2010 20:44:13 +0000
Subject: note 101229 deleted from function.xml-set-end-namespace-decl-handler by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-174596@lists.php.net to get a copy of this message
Note Submitter: Carlos Hernndez ---- I found this class (and simplified for this post) for to see xml_set_start_namespace_decl_handler function in action: ExampleXmlSaxParser.php <?php $p = new Parser; $p->startParser(); class Parser{ const READ_BLOCK_SIZE = 65536; private $location='extensions.rdf';//.rdf or .owl file. For example: extensions.rdf or downloads.rdf of firefox private $xmlParser = null; private $xmlBuffer = null; private $nestedElement = false; private $nsp; public function startParser() { // Set up the XML parser with namespaces support $this->xmlParser = xml_parser_create_ns('UTF-8', ''); // do not add extra separator xml_set_object($this->xmlParser, $this); xml_parser_set_option($this->xmlParser, XML_OPTION_CASE_FOLDING, false); xml_parser_set_option($this->xmlParser, XML_OPTION_TARGET_ENCODING, 'UTF-8'); xml_set_start_namespace_decl_handler($this->xmlParser, 'xmlStartNS'); $fh = gzopen($this->location, 'r'); while ($chunk = @fread($fh, self::READ_BLOCK_SIZE)) { if (!xml_parse($this->xmlParser, utf8_encode($chunk), feof($fh))) { fclose($fh); throw new Exception( 'XML error: ' . xml_error_string(xml_get_error_code($this>xmlParser)) . ' in ' . $this->location . ' line ' . xml_get_current_line_number($this->xmlParser) ); } } fclose($fh); if($this->xmlParser) { xml_parser_free($this->xmlParser); unset($this->xmlParser); } } private function xmlStartNS($parser, $prefix, $uri){ // ignore redefinition of a prefix if(empty($this->nsp[(string) $prefix])){ $this->nsp[(string) $prefix] = true; echo "xmlStartNS: $prefix = $uri\n"; } } } original link with complete source: http://gama-gateway.googlecode.com/svn/ trunk/GamaLib/classes/ExampleXmlSaxParser.php

« previous php.notes (#174596) next »