当前位置: 首页>>代码示例>>PHP>>正文


PHP xml_parse函数代码示例

本文整理汇总了PHP中xml_parse函数的典型用法代码示例。如果您正苦于以下问题:PHP xml_parse函数的具体用法?PHP xml_parse怎么用?PHP xml_parse使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了xml_parse函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: parse

 public function parse($xml_or_arr)
 {
     if (is_array($xml_or_arr)) {
         $output = array();
         foreach ($xml_or_arr as $val) {
             $to = $this->parse($val);
             $output = array_merge($output, $to);
         }
         return $output;
     }
     //		echo '<h1>xml in parser:</h1><pre>'; print_r($xml); echo '</pre>';
     // if we don't start with a processing instruction,
     // we add an outer node just to ensure it's a valid xml document
     // (i.e. only a single root node)
     if (substr($xml_or_arr, 0, 2) != '<?') {
         $xml_or_arr = "<{$this->insertedNode}>" . $xml_or_arr . "</{$this->insertedNode}>";
     }
     $this->parser = xml_parser_create();
     xml_set_object($this->parser, $this);
     xml_set_element_handler($this->parser, "tagOpen", "tagClosed");
     xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($this->parser, XML_OPTION_SKIP_WHITE, 1);
     xml_set_character_data_handler($this->parser, "tagData");
     $this->xmldata = xml_parse($this->parser, $xml_or_arr);
     if (!$this->xmldata) {
         die(sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser)));
     }
     xml_parser_free($this->parser);
     $this->parseCompleted();
     return $this->output;
 }
开发者ID:ilri,项目名称:genebank-gg_server,代码行数:31,代码来源:parsers.php

示例2: __construct

 /**
  * PHP5 constructor.
  */
 function __construct($source)
 {
     # Check if PHP xml isn't compiled
     #
     if (!function_exists('xml_parser_create')) {
         return trigger_error("PHP's XML extension is not available. Please contact your hosting provider to enable PHP's XML extension.");
     }
     $parser = xml_parser_create();
     $this->parser = $parser;
     # pass in parser, and a reference to this object
     # set up handlers
     #
     xml_set_object($this->parser, $this);
     xml_set_element_handler($this->parser, 'feed_start_element', 'feed_end_element');
     xml_set_character_data_handler($this->parser, 'feed_cdata');
     $status = xml_parse($this->parser, $source);
     if (!$status) {
         $errorcode = xml_get_error_code($this->parser);
         if ($errorcode != XML_ERROR_NONE) {
             $xml_error = xml_error_string($errorcode);
             $error_line = xml_get_current_line_number($this->parser);
             $error_col = xml_get_current_column_number($this->parser);
             $errormsg = "{$xml_error} at line {$error_line}, column {$error_col}";
             $this->error($errormsg);
         }
     }
     xml_parser_free($this->parser);
     $this->normalize();
 }
开发者ID:aaemnnosttv,项目名称:develop.git.wordpress.org,代码行数:32,代码来源:rss.php

示例3: _loadTranslationData

 /**
  * Load translation data (TBX file reader)
  *
  * @param  string  $filename  TBX file to add, full path must be given for access
  * @param  string  $locale    Locale has no effect for TBX because TBX defines all languages within
  *                            the source file
  * @param  array   $option    OPTIONAL Options to use
  * @throws Zend_Translation_Exception
  * @return array
  */
 protected function _loadTranslationData($filename, $locale, array $options = array())
 {
     $this->_data = array();
     if (!is_readable($filename)) {
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
     }
     $encoding = $this->_findEncoding($filename);
     $this->_file = xml_parser_create($encoding);
     xml_set_object($this->_file, $this);
     xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
     xml_set_element_handler($this->_file, "_startElement", "_endElement");
     xml_set_character_data_handler($this->_file, "_contentElement");
     try {
         Zend_Xml_Security::scanFile($filename);
     } catch (Zend_Xml_Exception $e) {
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception($e->getMessage());
     }
     if (!xml_parse($this->_file, file_get_contents($filename))) {
         $ex = sprintf('XML error: %s at line %d of file %s', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file), $filename);
         xml_parser_free($this->_file);
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception($ex);
     }
     return $this->_data;
 }
开发者ID:conectapb,项目名称:sysagroweb,代码行数:37,代码来源:Tbx.php

示例4: MagpieRSS

 function MagpieRSS($source)
 {
     # if PHP xml isn't compiled in, die
     #
     if (!function_exists('xml_parser_create')) {
         trigger_error("Failed to load PHP's XML Extension. http://www.php.net/manual/en/ref.xml.php");
     }
     $parser = @xml_parser_create();
     if (!is_resource($parser)) {
         trigger_error("Failed to create an instance of PHP's XML parser. http://www.php.net/manual/en/ref.xml.php");
     }
     $this->parser = $parser;
     # pass in parser, and a reference to this object
     # set up handlers
     #
     xml_set_object($this->parser, $this);
     xml_set_element_handler($this->parser, 'feed_start_element', 'feed_end_element');
     xml_set_character_data_handler($this->parser, 'feed_cdata');
     $status = xml_parse($this->parser, $source);
     if (!$status) {
         $errorcode = xml_get_error_code($this->parser);
         if ($errorcode != XML_ERROR_NONE) {
             $xml_error = xml_error_string($errorcode);
             $error_line = xml_get_current_line_number($this->parser);
             $error_col = xml_get_current_column_number($this->parser);
             $errormsg = "{$xml_error} at line {$error_line}, column {$error_col}";
             $this->error($errormsg);
         }
     }
     xml_parser_free($this->parser);
     $this->normalize();
 }
开发者ID:Esleelkartea,项目名称:herramienta_para_autodiagnostico_ADEADA,代码行数:32,代码来源:rss.php

示例5: loadXML

 function loadXML($file)
 {
     $this->_parser = xml_parser_create($this->getEncoding($file));
     // Auto detect for PHP4/PHP5
     xml_set_object($this->_parser, $this);
     xml_set_element_handler($this->_parser, "_saxStartElement", "_saxEndElement");
     xml_set_character_data_handler($this->_parser, "_saxCharacterData");
     xml_parser_set_option($this->_parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
     if ($fp = fopen($file, "r")) {
         $data = '';
         while (!feof($fp)) {
             $data .= fread($fp, 8192);
         }
         fclose($fp);
         // Strip slashes
         if (ini_get("magic_quotes_gpc")) {
             $data = stripslashes($data);
         }
         // XML parse
         if (!xml_parse($this->_parser, $data, true)) {
             trigger_error(sprintf("Language pack loading failed, XML error: %s at line %d.", xml_error_string(xml_get_error_code($this->_parser)), xml_get_current_line_number($this->_parser)), FATAL);
         }
     } else {
         trigger_error("Could not open XML language pack: " . $file, FATAL);
     }
     xml_parser_free($this->_parser);
 }
开发者ID:sonvq,项目名称:2015_freelance6,代码行数:27,代码来源:LanguageReader.php

示例6: parse

 function parse($xml)
 {
     $this->result = array();
     $this->context = $xml;
     $this->currentTag = '';
     $this->currentState = array();
     $this->xmlParser = xml_parser_create();
     xml_parser_set_option($this->xmlParser, XML_OPTION_TARGET_ENCODING, "UTF-8") . xml_set_object($this->xmlParser, $this);
     xml_set_element_handler($this->xmlParser, 'startElement', 'endElement');
     xml_set_character_data_handler($this->xmlParser, 'content');
     $this->trigger('before:import');
     try {
         if (!xml_parse($this->xmlParser, $xml)) {
             $this->xmlParserError = 'Line ' . xml_get_current_line_number($this->xmlParser) . ': ' . (xml_get_error_code($this->xmlParser) ? xml_error_string(xml_get_error_code($this->xmlParser)) : 'Unknown error');
         }
     } catch (Exception $e) {
         $this->xmlParserError = $e->getMessage();
     }
     xml_parser_free($this->xmlParser);
     if ($this->xmlParserError) {
         $this->raiseError($this->xmlParserError);
     } else {
         if ($this->getCurrentState()) {
             $this->raiseError('Wrong ending state: ' . $this->getCurrentState());
         } else {
         }
     }
     $this->trigger('after:import');
     return $this->result;
 }
开发者ID:jagermesh,项目名称:bright,代码行数:30,代码来源:BrXMLParser.php

示例7: _loadTranslationData

 /**
  * Load translation data (TMX file reader)
  *
  * @param  string  $filename  TMX file to add, full path must be given for access
  * @param  string  $locale    Locale has no effect for TMX because TMX defines all languages within
  *                            the source file
  * @param  array   $option    OPTIONAL Options to use
  * @throws Zend_Translation_Exception
  */
 protected function _loadTranslationData($filename, $locale, array $options = array())
 {
     $options = array_merge($this->_options, $options);
     if ($options['clear']) {
         $this->_translate = array();
     }
     if (in_array('defined_language', $options) and !empty($options['defined_language'])) {
         $this->_defined = true;
     }
     if (!is_readable($filename)) {
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception('Translation file \'' . $filename . '\' is not readable.');
     }
     $this->_file = xml_parser_create();
     xml_set_object($this->_file, $this);
     xml_parser_set_option($this->_file, XML_OPTION_CASE_FOLDING, 0);
     xml_set_element_handler($this->_file, "_startElement", "_endElement");
     xml_set_character_data_handler($this->_file, "_contentElement");
     if (!xml_parse($this->_file, file_get_contents($filename))) {
         $ex = sprintf('XML error: %s at line %d', xml_error_string(xml_get_error_code($this->_file)), xml_get_current_line_number($this->_file));
         xml_parser_free($this->_file);
         require_once 'Zend/Translate/Exception.php';
         throw new Zend_Translate_Exception($ex);
     }
 }
开发者ID:dalinhuang,项目名称:popo,代码行数:34,代码来源:Tmx.php

示例8: load

 function load($xml_file)
 {
     $this->_path = dirname($xml_file);
     if (!file_exists($xml_file)) {
         return;
     }
     $fp = @fopen($xml_file, "r");
     if ($fp) {
         $data = '';
         while (!feof($fp)) {
             $data .= fread($fp, 8192);
         }
         fclose($fp);
         if (ini_get("magic_quotes_gpc")) {
             $data = stripslashes($data);
         }
     }
     $this->_parser = xml_parser_create('UTF-8');
     xml_set_object($this->_parser, $this);
     xml_set_element_handler($this->_parser, "_saxStartElement", "_saxEndElement");
     xml_parser_set_option($this->_parser, XML_OPTION_TARGET_ENCODING, "UTF-8");
     if (!xml_parse($this->_parser, $data, true)) {
         trigger_error(sprintf("Language pack loading failed, XML error: %s at line %d.", xml_error_string(xml_get_error_code($this->_parser)), xml_get_current_line_number($this->_parser)), E_USER_ERROR);
     }
     xml_parser_free($this->_parser);
 }
开发者ID:Vladimir25,项目名称:marykay,代码行数:26,代码来源:ClientResources.php

示例9: parseFile

 function parseFile($persist = false)
 {
     if (empty($this->parser)) {
         error_log("No parser, so allocating new xml parser");
         $this->parser = xml_parser_create();
         xml_set_object($this->parser, $this);
         xml_set_element_handler($this->parser, "startHandler", "endHandler");
         xml_set_character_data_handler($this->parser, "cdataHandler");
     }
     if (!empty($this->file)) {
         // process & parse
         $fp = fopen($this->file, 'r');
         if ($fp) {
             // could read the file successfully
             while ($data = fread($fp, 4096)) {
                 xml_parse($this->parser, $data, feof($fp)) or error_log(sprintf("Error in parsing XML: %s at line %d", xml_error_string(xml_get_error_code($this->parser)), xml_get_current_line_number($this->parser)));
             }
             fclose($fp);
         } else {
             error_log("Could not read file (name: {$this->file}).");
         }
     } else {
         error_log("Could not parse. No file specified.");
     }
     if (!$persist) {
         xml_parser_free($this->parser);
     }
 }
开发者ID:emeraldion,项目名称:zelda,代码行数:28,代码来源:MURatingsParser.php

示例10: parse

 function parse()
 {
     xml_set_object($this->parser, $this);
     xml_set_element_handler($this->parser, "startElement", "endElement");
     xml_set_character_data_handler($this->parser, "characterData");
     return (bool) xml_parse($this->parser, file_get_contents($this->file), true);
 }
开发者ID:BackupTheBerlios,项目名称:mvc-hispano,代码行数:7,代码来源:class.xmlparser.php

示例11: Parse

 public function Parse($filename)
 {
     $root = new CNode(CNode::K_ROOT, $filename, CNode::T_ROOT);
     $filename = $root->Get(CNode::FLD_VAL);
     $xmlstring = file_get_contents($filename);
     if ($xmlstring === FALSE) {
         $root->SetErr("failed to read file {$filename}", CNode::E_FATAL);
         return $root;
     }
     $parser = xml_parser_create();
     xml_set_object($parser, $this);
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, false);
     xml_set_element_handler($parser, 'startElement', 'endElement');
     xml_set_character_data_handler($parser, 'characterData');
     // Build a Root node and initialize the node_stack...
     $this->node_stack = array();
     $this->cur_node = $root;
     // parse the data and free the parser...
     $result = xml_parse($parser, $xmlstring);
     if (!$result) {
         $err = 'XML error: ' . xml_error_string(xml_get_error_code($parser)) . ' at line ' . xml_get_current_line_number($parser);
         $root->SetErr("failed to parse file {$filename}, {$err}", CNode::E_FATAL);
     }
     xml_parser_free($parser);
     return $root;
 }
开发者ID:kopytov,项目名称:openlitespeed,代码行数:26,代码来源:XmlParser.php

示例12: _parseXML

 function _parseXML()
 {
     $this->items = array();
     $this->item = array();
     $this->is_item = FALSE;
     $this->tag = '';
     $this->level_base = 0;
     $buf = $this->src;
     // Detect encoding
     $matches = array();
     if (preg_match('/<\\?xml [^>]*\\bencoding="([a-z0-9-_]+)"/i', $buf, $matches)) {
         $this->encoding = $matches[1];
     } else {
         $this->encoding = mb_detect_encoding($buf, $this->detect_order);
     }
     // Normalize to UTF-8 / ASCII
     if (!in_array(strtolower($this->encoding), array('us-ascii', 'iso-8859-1', 'utf-8'))) {
         $buf = mb_convert_encoding($buf, 'utf-8', $this->encoding);
         $this->encoding = 'utf-8';
     }
     // Parsing
     $xml_parser = xml_parser_create($this->encoding);
     xml_set_element_handler($xml_parser, array(&$this, 'start_element'), array(&$this, 'end_element'));
     xml_set_character_data_handler($xml_parser, array(&$this, 'character_data'));
     if (!xml_parse($xml_parser, $buf, 1)) {
         return sprintf('XML error: %s at line %d in %s', xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser), $buf);
     }
     xml_parser_free($xml_parser);
     //return $this->items;
 }
开发者ID:nao-pon,项目名称:HypCommon,代码行数:30,代码来源:hyp_rss2html.php

示例13: parse

 public function parse($html)
 {
     // replace entities
     $html = preg_replace('/&([a-z0-9#]{2,5});/i', '+$1;', $html);
     //before sending to xml parser make sure we have valid xml by tidying it up
     $html = Kwf_Util_Tidy::repairHtml($html);
     $this->_stack = array();
     $this->_ret = '';
     $this->_parser = xml_parser_create();
     xml_set_object($this->_parser, $this);
     xml_set_element_handler($this->_parser, 'startElement', 'endElement');
     xml_set_character_data_handler($this->_parser, 'characterData');
     xml_set_default_handler($this->_parser, 'characterData');
     $result = xml_parse($this->_parser, '<body>' . $html . '</body>', true);
     if (!$result) {
         // wenn man ein nicht geschlossenes <br> rein gibt, schreit er hier,
         // macht aber normal weiter. wenns zu oft vorkommt, evtl. exception
         // entfernen und ignorieren, oder was andres überlegen :-)
         $errorCode = xml_get_error_code($this->_parser);
         $ex = new Kwf_Exception("HtmlExport UrlParser XML Error {$errorCode}: " . xml_error_string($errorCode) . "in line " . xml_get_current_line_number($this->_parser) . " parsed html: " . $html);
         $ex->logOrThrow();
     }
     // re-replace entities
     $this->_ret = preg_replace('/\\+([a-z0-9#]{2,5});/i', '&$1;', $this->_ret);
     return $this->_ret;
 }
开发者ID:xiaoguizhidao,项目名称:koala-framework,代码行数:26,代码来源:UrlParser.php

示例14: parse

 function parse()
 {
     set_error_handler(array(&$this, 'error_handler'));
     array_unshift($this->ns_contexts, array());
     $parser = xml_parser_create_ns();
     xml_set_object($parser, $this);
     xml_set_element_handler($parser, "start_element", "end_element");
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 0);
     xml_set_character_data_handler($parser, "cdata");
     xml_set_default_handler($parser, "_default");
     xml_set_start_namespace_decl_handler($parser, "start_ns");
     xml_set_end_namespace_decl_handler($parser, "end_ns");
     $this->content = '';
     $ret = true;
     $fp = fopen($this->FILE, "r");
     while ($data = fread($fp, 4096)) {
         if ($this->debug) {
             $this->content .= $data;
         }
         if (!xml_parse($parser, $data, feof($fp))) {
             trigger_error(sprintf(__('XML error: %s at line %d') . "\n", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser)));
             $ret = false;
             break;
         }
     }
     fclose($fp);
     xml_parser_free($parser);
     restore_error_handler();
     return $ret;
 }
开发者ID:helmonaut,项目名称:owb-mirror,代码行数:31,代码来源:atomlib.php

示例15: parseXml

 /**
  * Method parses a mirror.xml file.
  *
  * @param string $file GZIP stream resource
  * @return void
  * @throws \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException in case of XML parser errors
  */
 public function parseXml($file)
 {
     $this->createParser();
     if (!is_resource($this->objXml)) {
         throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException('Unable to create XML parser.', 1342641009);
     }
     // Disables the functionality to allow external entities to be loaded when parsing the XML, must be kept
     $previousValueOfEntityLoader = libxml_disable_entity_loader(true);
     // keep original character case of XML document
     xml_parser_set_option($this->objXml, XML_OPTION_CASE_FOLDING, false);
     xml_parser_set_option($this->objXml, XML_OPTION_SKIP_WHITE, false);
     xml_parser_set_option($this->objXml, XML_OPTION_TARGET_ENCODING, 'utf-8');
     xml_set_element_handler($this->objXml, 'startElement', 'endElement');
     xml_set_character_data_handler($this->objXml, 'characterData');
     if (!($fp = fopen($file, 'r'))) {
         throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('Unable to open file resource %s.', $file), 1342641010);
     }
     while ($data = fread($fp, 4096)) {
         if (!xml_parse($this->objXml, $data, feof($fp))) {
             throw new \TYPO3\CMS\Extensionmanager\Exception\ExtensionManagerException(sprintf('XML error %s in line %u of file resource %s.', xml_error_string(xml_get_error_code($this->objXml)), xml_get_current_line_number($this->objXml), $file), 1342641011);
         }
     }
     libxml_disable_entity_loader($previousValueOfEntityLoader);
     xml_parser_free($this->objXml);
 }
开发者ID:dachcom-digital,项目名称:TYPO3.CMS,代码行数:32,代码来源:MirrorXmlPushParser.php


注:本文中的xml_parse函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。