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


PHP xml_get_current_byte_index函数代码示例

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


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

示例1: formatMetadata

 /**
  * Format resource metadata.
  *
  * @param resource $value
  *
  * @return string
  */
 protected function formatMetadata($value)
 {
     $props = array();
     switch (get_resource_type($value)) {
         case 'stream':
             $props = stream_get_meta_data($value);
             break;
         case 'curl':
             $props = curl_getinfo($value);
             break;
         case 'xml':
             $props = array('current_byte_index' => xml_get_current_byte_index($value), 'current_column_number' => xml_get_current_column_number($value), 'current_line_number' => xml_get_current_line_number($value), 'error_code' => xml_get_error_code($value));
             break;
     }
     if (empty($props)) {
         return '{}';
     }
     $formatted = array();
     foreach ($props as $name => $value) {
         $formatted[] = sprintf('%s: %s', $name, $this->indentValue($this->presentSubValue($value)));
     }
     $template = sprintf('{%s%s%%s%s}', PHP_EOL, self::INDENT, PHP_EOL);
     $glue = sprintf(',%s%s', PHP_EOL, self::INDENT);
     return sprintf($template, implode($glue, $formatted));
 }
开发者ID:GeorgeShazkho,项目名称:micros-de-conce,代码行数:32,代码来源:ResourcePresenter.php

示例2: _startElement

 protected function _startElement($parser, $name, $attrs)
 {
     if (strpos($name, ':') === false) {
         throw new Exception('Invalid element name: ' . $name . '.');
     }
     if ($name === RDF_NS . 'RDF') {
         if (isset($attrs[XML_NS . 'base'])) {
             $this->_baseUri = $attrs[XML_NS . 'base'];
         }
         return;
     }
     $idx = xml_get_current_byte_index($parser) - $this->_offset * 4096;
     if ($idx >= 0 && $this->_data[$idx] . $this->_data[$idx + 1] === '/>') {
         $this->_currentElementIsEmpty = true;
     } else {
         $this->_currentElementIsEmpty = false;
     }
     if (isset($attrs['http://www.w3.org/XML/1998/namespacelang'])) {
         $this->_currentXmlLang = $attrs['http://www.w3.org/XML/1998/namespacelang'];
     }
     if ($this->_topElemIsProperty()) {
         // In this case the surrounding element is a property, so this element is a s and/or o.
         $this->_processNode($name, $attrs);
     } else {
         // This element is a property.
         $this->_processProperty($name, $attrs);
     }
 }
开发者ID:portokallidis,项目名称:Metamorphosis-Meducator,代码行数:28,代码来源:SPRdfXmlParser.inc.php

示例3: castXml

 public static function castXml($h, array $a, Stub $stub, $isNested)
 {
     $a['current_byte_index'] = xml_get_current_byte_index($h);
     $a['current_column_number'] = xml_get_current_column_number($h);
     $a['current_line_number'] = xml_get_current_line_number($h);
     $a['error_code'] = xml_get_error_code($h);
     if (isset(self::$xmlErrors[$a['error_code']])) {
         $a['error_code'] = new ConstStub(self::$xmlErrors[$a['error_code']], $a['error_code']);
     }
     return $a;
 }
开发者ID:JesseDarellMoore,项目名称:CS499,代码行数:11,代码来源:XmlResourceCaster.php

示例4: __construct

 public function __construct($message, $parser, \SplFileObject $file = NULL)
 {
     $this->code = xml_get_error_code($parser);
     if (false === $this->code) {
         throw new \BadMethodCallException('This is not a valid xml_parser resource.');
     }
     parent::__construct($message ?: xml_error_string($this->code), $this->code);
     $this->file = $file ? $file->getPathname() : '(data stream)';
     $this->line = xml_get_current_line_number($parser);
     $this->err['srcColumn'] = xml_get_current_column_number($parser);
     $this->err['srcIndex'] = xml_get_current_byte_index($parser);
 }
开发者ID:anrdaemon,项目名称:library,代码行数:12,代码来源:XmlParserError.php

示例5: parse

 /**
  * @ignore
  */
 private function parse($xml)
 {
     $xml_parser = xml_parser_create();
     xml_set_object($xml_parser, $this);
     xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, false);
     xml_set_element_handler($xml_parser, array(&$this, "startElement"), array(&$this, "endElement"));
     xml_set_character_data_handler($xml_parser, array(&$this, "characterData"));
     //        xml_set_default_handler($xml_parser, array(&$this, "defaultHandler"));
     if (!xml_parse($xml_parser, $xml, true)) {
         echo 'MetaValue error: ' . xml_error_string($xml_parser) . '<br>' . 'Error line: ' . xml_get_current_line_number($xml_parser) . '<br>' . 'Byte number error: ' . xml_get_current_byte_index($xml_parser) . '<br><br>';
     }
     xml_parser_free($xml_parser);
 }
开发者ID:rebe100x,项目名称:YAKREP,代码行数:16,代码来源:MetaValue.php

示例6: parse

 function parse($url)
 {
     $values = "";
     $encoding = 'UTF-8';
     $data = file_get_contents($url);
     $parser = xml_parser_create($encoding);
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     $ok = xml_parse_into_struct($parser, $data, $values);
     if (!$ok) {
         $errmsg = sprintf("XML parse error %d '%s' at line %d, column %d (byte index %d)", xml_get_error_code($parser), xml_error_string(xml_get_error_code($parser)), xml_get_current_line_number($parser), xml_get_current_column_number($parser), xml_get_current_byte_index($parser));
     }
     xml_parser_free($parser);
     return $this->reorganize($values);
 }
开发者ID:Nnamso,项目名称:tbox,代码行数:15,代码来源:xml.php

示例7: import

 /**
  * Import HTML from $source to $target node.
  *
  * @param \DOMElement $source
  * @param \DOMElement $target
  *
  * @since 1.0
  */
 public static function import(\DOMElement $source, \DOMElement $target)
 {
     /* Prepare container */
     $container = $target->ownerDocument->createElement('xhtml:div');
     $container->setAttributeNS(Atom::XMLNS, 'xmlns:xhtml', Atom::XHTML);
     $target->appendChild($container);
     /* Prefix all source tags with "xhtml:" */
     $xmlFrom = $source->ownerDocument->saveXML($source);
     $xmlTo = '';
     $xhtmlNsSet = false;
     $parser = xml_parser_create('UTF-8');
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     xml_set_element_handler($parser, function ($parser, $name, array $attrs) use($xmlFrom, &$xmlTo, &$xhtmlNsSet) {
         $selfClosing = '/>' === substr($xmlFrom, xml_get_current_byte_index($parser), 2);
         $xmlTo .= '<xhtml:' . $name;
         if (false === $xhtmlNsSet) {
             $attrs['xmlns:xhtml'] = Atom::XHTML;
             $xhtmlNsSet = true;
         }
         foreach ($attrs as $attr => $value) {
             $xmlTo .= sprintf(' %s="%s"', $attr, htmlspecialchars($value, ENT_COMPAT | ENT_XML1));
         }
         $xmlTo .= $selfClosing ? '/>' : '>';
     }, function ($parser, $name) use($xmlFrom, &$xmlTo) {
         $selfClosing = '/>' === substr($xmlFrom, xml_get_current_byte_index($parser) - 2, 2);
         if ($selfClosing) {
             return;
         }
         $xmlTo .= '</xhtml:' . $name . '>';
     });
     xml_set_default_handler($parser, function ($parser, $data) use(&$xmlTo) {
         $xmlTo .= $data;
     });
     xml_parse($parser, $xmlFrom, true);
     xml_parser_free($parser);
     /* Import prefixed XML into container */
     $tmpDoc = new \DOMDocument('1.0', 'utf-8');
     $tmpDoc->loadXML($xmlTo);
     foreach ($tmpDoc->documentElement->childNodes as $node) {
         $container->appendChild($container->ownerDocument->importNode($node, true));
     }
 }
开发者ID:mekras,项目名称:atom,代码行数:50,代码来源:Xhtml.php

示例8: parse

 function parse()
 {
     // Creates the object tree from XML code
     $success = true;
     $error = array();
     $this->parser = xml_parser_create($this->encoding);
     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, "defaultHandler");
     if (!xml_parse($this->parser, $this->xml)) {
         // Error while parsing document
         $success = false;
         $error['err_code'] = $err_code = xml_get_error_code($this->parser);
         $error['err_string'] = xml_error_string($err_code);
         $error['err_line'] = xml_get_current_line_number($this->parser);
         $error['err_col'] = xml_get_current_column_number($this->parser);
         $error['err_byte'] = xml_get_current_byte_index($this->parser);
         //print "<p><b>Error Code:</b> $err_code<br>$err_string<br><b>Line:</b> $err_line<br><b>Column: $err_col</p>";
     }
     xml_parser_free($this->parser);
     return $success === true ? true : $error;
 }
开发者ID:KICHIRO20,项目名称:-Myproject_part1-,代码行数:23,代码来源:obj_xml.php

示例9: parse

 function parse($schema)
 {
     $this->parser = xml_parser_create($this->encoding);
     if (!$this->parser) {
         $this->error = 'Relax Error: Failed to create an XML parser!';
         return false;
     }
     if (!xml_parser_set_option($this->parser, XML_OPTION_CASE_FOLDING, false)) {
         xml_parser_free($this->parser);
         $this->error = 'Relax Error: Failed to disable case folding!';
         return false;
     }
     $this->schema = $schema;
     //$this->elements = array ();
     //$this->parents = array ();
     //$this->attrs = array ();
     $this->attrOpen = false;
     $this->definitions = array();
     $this->addUntil = false;
     $this->error = false;
     $this->rule = 'required';
     if (xml_parse_into_struct($this->parser, $schema, $this->nodes, $this->tags)) {
         xml_parser_free($this->parser);
         foreach ($this->nodes as $node) {
             $this->{$this->makeMethod($node['tag'], $node['type'])}($node);
         }
         return $this->rules;
     } else {
         $this->err_code = xml_get_error_code($this->parser);
         $this->err_line = xml_get_current_line_number($this->parser);
         $this->err_byte = xml_get_current_byte_index($this->parser);
         $this->err_colnum = xml_get_current_column_number($this->parser);
         $this->error = 'Relax Error: ' . xml_error_string($this->err_code);
         xml_parser_free($this->parser);
         return false;
     }
 }
开发者ID:vojtajina,项目名称:sitellite,代码行数:37,代码来源:Parser.php

示例10: SetError

 function SetError($error_number, $error)
 {
     $this->error_number = $error_number;
     $this->error = $error;
     if ($this->xml_parser) {
         $line = xml_get_current_line_number($this->xml_parser);
         $column = xml_get_current_column_number($this->xml_parser);
         $byte_index = xml_get_current_byte_index($this->xml_parser);
     } else {
         $line = $column = 1;
         $byte_index = 0;
     }
     $this->SetErrorPosition($error_number, $error, $line, $column, $byte_index);
 }
开发者ID:BackupTheBerlios,项目名称:zvs,代码行数:14,代码来源:xml_parser.php

示例11: parse

 /**
  * Parses xml text using Expat
  * @param Object A reference to the DOM document that the xml is to be parsed into
  * @param string The text to be parsed
  * @param boolean True if CDATA Section nodes are not to be converted into Text nodes
  * @return boolean True if the parsing is successful
  */
 function parse(&$myXMLDoc, $xmlText, $preserveCDATA = true)
 {
     $this->xmlDoc =& $myXMLDoc;
     $this->lastChild =& $this->xmlDoc;
     $this->preserveCDATA = $preserveCDATA;
     //create instance of expat parser (should be included in php distro)
     if (version_compare(phpversion(), '5.0', '<=')) {
         $parser =& xml_parser_create('');
     } else {
         $parser =& xml_parser_create();
     }
     //set handlers for SAX events
     xml_set_object($parser, $this);
     xml_set_element_handler($parser, 'startElement', 'endElement');
     xml_set_character_data_handler($parser, 'dataElement');
     xml_set_default_handler($parser, 'defaultDataElement');
     xml_parser_set_option($parser, XML_OPTION_CASE_FOLDING, 0);
     xml_parser_set_option($parser, XML_OPTION_SKIP_WHITE, 1);
     //parse out whitespace -  (XML_OPTION_SKIP_WHITE = 1 does not
     //seem to work consistently across versions of PHP and Expat
     $xmlText = eregi_replace('>' . "[[:space:]]+" . '<', '><', $xmlText);
     $success = xml_parse($parser, $xmlText);
     $this->xmlDoc->errorCode = xml_get_error_code($parser);
     $this->xmlDoc->errorString = xml_error_string($this->xmlDoc->errorCode) . ' at line ' . xml_get_current_line_number($parser) . ', column ' . xml_get_current_column_number($parser) . ', byte ' . xml_get_current_byte_index($parser);
     xml_parser_free($parser);
     return $success;
 }
开发者ID:jwest00724,项目名称:mambo,代码行数:34,代码来源:xml_domit_lite_parser.php

示例12: parse

 public function parse(&$data, $encoding)
 {
     // Use UTF-8 if we get passed US-ASCII, as every US-ASCII character is a UTF-8 character
     if (strtoupper($encoding) === 'US-ASCII') {
         $this->encoding = 'UTF-8';
     } else {
         $this->encoding = $encoding;
     }
     // Strip BOM:
     // UTF-32 Big Endian BOM
     if (substr($data, 0, 4) === "��") {
         $data = substr($data, 4);
     } elseif (substr($data, 0, 4) === "��") {
         $data = substr($data, 4);
     } elseif (substr($data, 0, 2) === "��") {
         $data = substr($data, 2);
     } elseif (substr($data, 0, 2) === "��") {
         $data = substr($data, 2);
     } elseif (substr($data, 0, 3) === "") {
         $data = substr($data, 3);
     }
     if (substr($data, 0, 5) === '<?xml' && strspn(substr($data, 5, 1), "\t\n\r ") && ($pos = strpos($data, '?>')) !== false) {
         $declaration = $this->registry->create('XML_Declaration_Parser', array(substr($data, 5, $pos - 5)));
         if ($declaration->parse()) {
             $data = substr($data, $pos + 2);
             $data = '<?xml version="' . $declaration->version . '" encoding="' . $encoding . '" standalone="' . ($declaration->standalone ? 'yes' : 'no') . '"?>' . $data;
         } else {
             $this->error_string = 'SimplePie bug! Please report this!';
             return false;
         }
     }
     $return = true;
     static $xml_is_sane = null;
     if ($xml_is_sane === null) {
         $parser_check = xml_parser_create();
         xml_parse_into_struct($parser_check, '<foo>&amp;</foo>', $values);
         xml_parser_free($parser_check);
         $xml_is_sane = isset($values[0]['value']);
     }
     // Create the parser
     if ($xml_is_sane) {
         $xml = xml_parser_create_ns($this->encoding, $this->separator);
         xml_parser_set_option($xml, XML_OPTION_SKIP_WHITE, 1);
         xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, 0);
         xml_set_object($xml, $this);
         xml_set_character_data_handler($xml, 'cdata');
         xml_set_element_handler($xml, 'tag_open', 'tag_close');
         // Parse!
         if (!xml_parse($xml, $data, true)) {
             $this->error_code = xml_get_error_code($xml);
             $this->error_string = xml_error_string($this->error_code);
             $return = false;
         }
         $this->current_line = xml_get_current_line_number($xml);
         $this->current_column = xml_get_current_column_number($xml);
         $this->current_byte = xml_get_current_byte_index($xml);
         xml_parser_free($xml);
         return $return;
     } else {
         libxml_clear_errors();
         $xml = new XMLReader();
         $xml->xml($data);
         while (@$xml->read()) {
             switch ($xml->nodeType) {
                 case constant('XMLReader::END_ELEMENT'):
                     if ($xml->namespaceURI !== '') {
                         $tagName = $xml->namespaceURI . $this->separator . $xml->localName;
                     } else {
                         $tagName = $xml->localName;
                     }
                     $this->tag_close(null, $tagName);
                     break;
                 case constant('XMLReader::ELEMENT'):
                     $empty = $xml->isEmptyElement;
                     if ($xml->namespaceURI !== '') {
                         $tagName = $xml->namespaceURI . $this->separator . $xml->localName;
                     } else {
                         $tagName = $xml->localName;
                     }
                     $attributes = array();
                     while ($xml->moveToNextAttribute()) {
                         if ($xml->namespaceURI !== '') {
                             $attrName = $xml->namespaceURI . $this->separator . $xml->localName;
                         } else {
                             $attrName = $xml->localName;
                         }
                         $attributes[$attrName] = $xml->value;
                     }
                     $this->tag_open(null, $tagName, $attributes);
                     if ($empty) {
                         $this->tag_close(null, $tagName);
                     }
                     break;
                 case constant('XMLReader::TEXT'):
                 case constant('XMLReader::CDATA'):
                     $this->cdata(null, $xml->value);
                     break;
             }
         }
         if ($error = libxml_get_last_error()) {
//.........这里部分代码省略.........
开发者ID:sevengage,项目名称:feed-merge,代码行数:101,代码来源:SimplePie.php

示例13: raiseError

 /**
  * Raise an error
  * @param string error message
  * @access private
  * @return void
  */
 function raiseError($msg)
 {
     $this->isError = TRUE;
     $msg .= ' [byte index: ' . xml_get_current_byte_index($this->parser) . ']';
     trigger_error($msg, E_USER_ERROR);
 }
开发者ID:BackupTheBerlios,项目名称:k4bb,代码行数:12,代码来源:XML.php

示例14: run

 public function run()
 {
     $xml = xml_parser_create();
     xml_set_element_handler($xml, [&$this, "start"], [&$this, "end"]);
     xml_set_character_data_handler($xml, [&$this, "data"]);
     xml_parser_set_option($xml, XML_OPTION_CASE_FOLDING, false);
     $totalFileSize = filesize($this->iFileName);
     $processed = 0;
     $this->log("Processed: 0%\r");
     while ($data = fread($this->iFh, 4096)) {
         if (!xml_parse($xml, $data, feof($this->iFh))) {
             throw new \RuntimeException(sprintf('XML parser error %s: %s at line %s at column %s (byte index %s)', xml_get_error_code($xml), xml_error_string(xml_get_error_code($xml)), xml_get_current_line_number($xml), xml_get_current_column_number($xml), xml_get_current_byte_index($xml)));
         }
         $processed += 4096;
         $percentage = round($processed / $totalFileSize * 100, 2);
         $this->log("Processed: {$percentage}%\r");
     }
     xml_parser_free($xml);
     $this->log('Processed: 100%                                 ');
 }
开发者ID:kluevandrew,项目名称:mysql2postgresql,代码行数:20,代码来源:Converter.php

示例15: baseParserClass

 $rss_parser = new baseParserClass("rss2html");
 $rss_parser->noFutureItems = $NoFutureItems;
 $rss_parser->wholeString = $convertedXML;
 xml_set_object($xml_parser, $rss_parser);
 xml_set_element_handler($xml_parser, "startElement", "endElement");
 xml_set_character_data_handler($xml_parser, "characterData");
 xml_parser_set_option($xml_parser, XML_OPTION_CASE_FOLDING, 1);
 $parseResult = xml_parse($xml_parser, $convertedXML, TRUE);
 if ($parseResult == 0) {
     if (!isset($hideErrors)) {
         $errorCode = xml_get_error_code($xml_parser);
         echo "\$errorCode = {$errorCode}<br>\n";
         echo "xml_error_string() = " . xml_error_string($errorCode) . "<br>\n";
         echo "xml_get_current_line_number() = " . xml_get_current_line_number($xml_parser) . "<br>\n";
         echo "xml_get_current_column_number() = " . xml_get_current_column_number($xml_parser) . "<br>\n";
         echo "xml_get_current_byte_index() = " . xml_get_current_byte_index($xml_parser) . "<br>\n";
     }
 } else {
     xml_parser_free($xml_parser);
     // make sure the channel contentEncoded is not blank
     if ($rss_parser->FeedContentEncoded == "") {
         $rss_parser->FeedContentEncoded = $rss_parser->FeedDescription;
     }
     $template = FeedForAll_rss2html_str_replace("~~~FeedXMLFilename~~~", FeedForAll_rss2html_EscapeLink($XMLfilename), $template);
     $template = FeedForAll_rss2html_str_replace("~~~FeedTitle~~~", FeedForAll_rss2html_limitLength($rss_parser->FeedTitle, $limitFeedTitleLength), $template);
     $template = FeedForAll_rss2html_str_replace("~~~FeedDescription~~~", FeedForAll_rss2html_limitLength($rss_parser->FeedDescription, $limitFeedDescriptionLength), $template);
     $template = FeedForAll_rss2html_str_replace("~~~FeedContentEncoded~~~", $rss_parser->FeedContentEncoded, $template);
     $template = FeedForAll_rss2html_str_replace("~~~FeedLink~~~", FeedForAll_rss2html_EscapeLink($rss_parser->FeedLink), $template);
     $template = FeedForAll_rss2html_str_replace("~~~FeedPubDate~~~", $rss_parser->FeedPubDate, $template);
     $template = FeedForAll_rss2html_str_replace("~~~FeedPubLongDate~~~", date($LongDateFormat, $rss_parser->FeedPubDate_t), $template);
     $template = FeedForAll_rss2html_str_replace("~~~FeedPubShortDate~~~", date($ShortDateFormat, $rss_parser->FeedPubDate_t), $template);
开发者ID:msehalic,项目名称:zamger,代码行数:31,代码来源:rss2html.php


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