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


PHP XMLReader::moveToFirstAttribute方法代码示例

本文整理汇总了PHP中XMLReader::moveToFirstAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP XMLReader::moveToFirstAttribute方法的具体用法?PHP XMLReader::moveToFirstAttribute怎么用?PHP XMLReader::moveToFirstAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在XMLReader的用法示例。


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

示例1: parse

 protected function parse()
 {
     $depth = 0;
     $elements = array();
     $elements_[$depth] =& $elements;
     while ($this->xml->read()) {
         switch ($this->xml->nodeType) {
             case XMLReader::END_ELEMENT:
                 if ($this->xml->depth - 1 < $depth) {
                     $elements =& $elements_[$depth];
                     $element =& $elements[sizeof($elements) - 1];
                     $depth = $this->xml->depth - 1;
                 }
                 break;
             case XMLReader::ATTRIBUTE:
                 # Read does not go through attributes :(
                 break;
             case XMLReader::ELEMENT:
                 if (strlen($this->xml->name) == 0) {
                     continue;
                 }
                 if ($this->xml->depth > $depth) {
                     $depth = $this->xml->depth;
                     $elements_[$depth] =& $elements;
                     $elements =& $element['elements'];
                 }
                 $elements[] = array('tag' => $this->xml->name);
                 # Working Element
                 $element =& $elements[sizeof($elements) - 1];
                 # Attributes
                 if ($this->xml->hasAttributes) {
                     $this->xml->moveToFirstAttribute();
                     $element['attributes'] = array();
                     $element['attributes'][$this->xml->name] = $this->xml->value;
                     while ($this->xml->moveToNextAttribute()) {
                         $element['attributes'][$this->xml->name] = $this->xml->value;
                     }
                 }
                 if ($this->xml->isEmptyElement) {
                     if ($this->xml->depth - 1 < $depth) {
                         $elements =& $elements_[$depth];
                         $element =& $elements[sizeof($elements) - 1];
                         $depth = $this->xml->depth - 1;
                     }
                 }
                 break;
             case XMLReader::TEXT:
             case XMLReader::CDATA:
                 if (!isset($element['value'])) {
                     $element['value'] = $this->xml->value;
                 } else {
                     $element['value'] .= $this->xml->value;
                 }
                 break;
         }
     }
     $this->elements = $elements;
 }
开发者ID:joksnet,项目名称:php-old,代码行数:58,代码来源:Reader.php

示例2: writeReaderImpl

 private function writeReaderImpl(XMLWriter $writer, XMLReader $reader)
 {
     switch ($reader->nodeType) {
         case XMLReader::ELEMENT:
             $writer->startElement($reader->name);
             if ($reader->moveToFirstAttribute()) {
                 do {
                     $writer->writeAttribute($reader->name, $reader->value);
                 } while ($reader->moveToNextAttribute());
                 $reader->moveToElement();
             }
             if ($reader->isEmptyElement) {
                 $writer->endElement();
             }
             break;
         case XMLReader::END_ELEMENT:
             $writer->endElement();
             break;
         case XMLReader::COMMENT:
             $writer->writeComment($reader->value);
             break;
         case XMLReader::SIGNIFICANT_WHITESPACE:
         case XMLReader::TEXT:
             $writer->text($reader->value);
             break;
         case XMLReader::PI:
             $writer->writePi($reader->name, $reader->value);
             break;
         default:
             XMLReaderNode::dump($reader);
     }
 }
开发者ID:hakre,项目名称:xmlreaderiterator,代码行数:32,代码来源:XMLWritingIteration.php

示例3: parse

 public function parse(\XMLReader $xmlReader, $startingDepth = 0, $parseOne = false)
 {
     if ($this->callback !== null) {
         $node = new Node();
         $node->name = $xmlReader->name;
         $node->depth = $xmlReader->depth;
         $node->text = $xmlReader->readString();
         if ($xmlReader->hasAttributes && $xmlReader->moveToFirstAttribute()) {
             do {
                 $node->attributes[$xmlReader->name] = $xmlReader->value;
             } while ($xmlReader->moveToNextAttribute());
             $xmlReader->moveToElement();
         }
         $callback = $this->callback;
         $callback($this->processNode($node, $xmlReader));
     }
 }
开发者ID:rhubarbphp,项目名称:rhubarb,代码行数:17,代码来源:NodeStrategyRead.php

示例4: dirname

<?php

/* $Id$ */
$filename = dirname(__FILE__) . '/_004.xml';
$xmlstring = '<?xml version="1.0" encoding="UTF-8"?>
<books><book num="1" idx="2">book1</book></books>';
file_put_contents($filename, $xmlstring);
$reader = new XMLReader();
if (!$reader->open($filename)) {
    exit;
}
while ($reader->read()) {
    if ($reader->nodeType != XMLREADER::END_ELEMENT) {
        echo $reader->name . "\n";
        if ($reader->nodeType == XMLREADER::ELEMENT && $reader->hasAttributes) {
            $attr = $reader->moveToFirstAttribute();
            while ($attr) {
                echo "   Attribute Name: " . $reader->name . "\n";
                echo "   Attribute Value: " . $reader->value . "\n";
                $attr = $reader->moveToNextAttribute();
            }
        }
    }
}
$reader->close();
unlink($filename);
?>
===DONE===
开发者ID:badlamer,项目名称:hhvm,代码行数:28,代码来源:004.php

示例5: while

                    $owl->moveToAttributeNo($n);
                    print $owl->name . ' = "' . $owl->value . "\"\n";
                }
                $owl->read();
                print $owl->value . "\n";
            }
            $owl->read();
        }
    }
    if ($owl->nodeType == XMLReader::ELEMENT && $owl->name == "rdf:Description") {
        while ($owl->nodeType != XMLReader::END_ELEMENT || $owl->name != "rdf:Description") {
            if ($owl->nodeType == XMLReader::ELEMENT) {
                print "ELEMENT" . $owl->name . "\n";
                if ($owl->hasAttributes && $owl->nodeType == XMLReader::ELEMENT) {
                    for ($n = 0; $n < $owl->attributeCount; $n++) {
                        $owl->moveToFirstAttribute();
                        print $owl->name . " = ";
                        print $owl->value . "\n";
                    }
                }
            }
            $owl->read();
        }
    }
}
//if ($owl->nodeType == XMLReader::ELEMENT)
//{
// Build the section array.
//if ($owl->hasAttributes&&$owl->nodeType==XMLReader::ELEMENT)
//{
//for ($n=0;$n<$owl->attributeCount;$n++)
开发者ID:spficklin,项目名称:OWL-XML-parser-into-Chado,代码行数:31,代码来源:joshhelp_parser.php

示例6: initFromReader

 /**
  * Initializes this Link from an XML reader.
  *
  * @param \XMLReader $xml The reader to use to initialize this object.
  */
 public function initFromReader($xml)
 {
     $empty = $xml->isEmptyElement;
     if ($xml->hasAttributes) {
         $moreAttributes = $xml->moveToFirstAttribute();
         while ($moreAttributes) {
             if (!$this->setKnownAttribute($xml)) {
                 //skip unknown attributes...
             }
             $moreAttributes = $xml->moveToNextAttribute();
         }
     }
     if (!$empty) {
         $xml->read();
         while ($xml->nodeType != \XMLReader::END_ELEMENT) {
             if ($xml->nodeType != \XMLReader::ELEMENT) {
                 //no-op: skip any insignificant whitespace, comments, etc.
             } else {
                 if (!$this->setKnownChildElement($xml)) {
                     $n = $xml->localName;
                     $ns = $xml->namespaceURI;
                     //skip the unknown element
                     while ($xml->nodeType != \XMLReader::END_ELEMENT && $xml->localName != $n && $xml->namespaceURI != $ns) {
                         $xml->read();
                     }
                 }
             }
             $xml->read();
             //advance the reader.
         }
     }
 }
开发者ID:BRGWeb,项目名称:gedcomx-php,代码行数:37,代码来源:Link.php

示例7: while

             $owl->read();
             print $owl->value . "\n";
         }
         $owl->read();
     }
 }
 // Section of the Owl Object Property read
 if ($owl->nodeType == XMLReader::ELEMENT && $owl->name == "owl:ObjectProperty") {
     $lname = "";
     while ($owl->nodeType != XMLReader::END_ELEMENT || $owl->name != "owl:ObjectProperty") {
         if ($owl->nodeType == XMLReader::ELEMENT) {
             $lname = $owl->name;
             print "ELEMENT " . $owl->name . "\n";
             if ($owl->hasAttributes) {
                 for ($n = 0; $n < $owl->attributeCount; $n++) {
                     $owl->moveToFirstAttribute($n);
                     print $owl->name . " = " . $owl->value . "\"\n";
                 }
             }
         }
         if ($owl->nodeType == XMLReader::TEXT) {
             print "VALUE " . $lname . " = " . $owl->value . "\n";
         }
         $owl->read();
     }
 }
 // Section of the Owl Class read
 if ($owl->nodeType == XMLReader::ELEMENT && $owl->name == "owl:Class") {
     $lname = "";
     while ($owl->nodeType != XMLReader::END_ELEMENT || $owl->name != "owl:Class") {
         if ($owl->nodeType == XMLReader::ELEMENT) {
开发者ID:spficklin,项目名称:OWL-XML-parser-into-Chado,代码行数:31,代码来源:xmltest1_parser.php

示例8: getAttributes

 /**
  * Returns the given node's attributes as an associative array
  *
  * @param \XMLReader $reader
  *
  * @return array
  */
 protected function getAttributes(\XMLReader $reader)
 {
     if (!$reader->hasAttributes) {
         return array();
     }
     $attributes = array();
     $reader->moveToFirstAttribute();
     do {
         $attributes[($reader->prefix ? $reader->prefix . ':' : '') . $reader->localName] = $reader->value;
     } while ($reader->moveToNextAttribute());
     $reader->moveToElement();
     return $attributes;
 }
开发者ID:bluem,项目名称:xmltransformer,代码行数:20,代码来源:XMLTransformer.php

示例9: initFromReader

 /**
  * Initializes this Identifier from an XML reader.
  *
  * @param \XMLReader $xml The reader to use to initialize this object.
  */
 public function initFromReader($xml)
 {
     $empty = $xml->isEmptyElement;
     if ($xml->hasAttributes) {
         $moreAttributes = $xml->moveToFirstAttribute();
         while ($moreAttributes) {
             if (!$this->setKnownAttribute($xml)) {
                 //skip unknown attributes...
             }
             $moreAttributes = $xml->moveToNextAttribute();
         }
     }
     if (!$empty) {
         $this->value = '';
         while ($xml->read() && $xml->hasValue) {
             $this->value = $this->value . $xml->value;
         }
     }
 }
开发者ID:BRGWeb,项目名称:gedcomx-php,代码行数:24,代码来源:Identifier.php

示例10: parse

 /**
  * Parses the input code and returns the OPT XML tree.
  *
  * @param String $filename The file name (for debug purposes)
  * @param String &$code The code to parse
  * @return Opt_Xml_Root
  */
 public function parse($filename, &$code)
 {
     $debug = array(XMLReader::NONE => 'NONE', XMLReader::ELEMENT => 'ELEMENT', XMLReader::ATTRIBUTE => 'ATTRIBUTE', XMLReader::TEXT => 'TEXT', XMLReader::CDATA => 'CDATA', XMLReader::ENTITY_REF => 'ENTITY_REF', XMLReader::ENTITY => 'ENTITY', XMLReader::PI => 'PI', XMLReader::COMMENT => 'COMMENT', XMLReader::DOC => 'DOC', XMLReader::DOC_TYPE => 'DOC_TYPE', XMLReader::DOC_FRAGMENT => 'DOC_FRAGMENT', XMLReader::NOTATION => 'NOTATION', XMLReader::WHITESPACE => 'WHITESPACE', XMLReader::SIGNIFICANT_WHITESPACE => 'SIGNIFICANT_WHITESPACE', XMLReader::END_ELEMENT => 'END_ELEMENT', XMLReader::END_ENTITY => 'END_ENTITY', XMLReader::XML_DECLARATION => 'XML_DECLARATION');
     libxml_use_internal_errors(true);
     $reader = new XMLReader();
     $reader->xml($code);
     //	$reader->setParserProperty(XMLReader::LOADDTD, true);
     //	$reader->setParserProperty(XMLReader::VALIDATE, true);
     $reader->setParserProperty(XMLReader::SUBST_ENTITIES, true);
     $root = $current = new Opt_Xml_Root();
     $firstElementMatched = false;
     $depth = 0;
     // Thanks, Oh Great PHP for your excellent WARNINGS!!! >:(
     while (@$reader->read()) {
         if ($reader->depth < $depth) {
             $current = $current->getParent();
         } elseif ($reader->depth > $depth) {
             $current = $optNode;
         }
         //	Opl_Debug::write($debug[$reader->nodeType].': '.$reader->name.', '.$reader->value);
         switch ($reader->nodeType) {
             // XML elements
             case XMLReader::ELEMENT:
                 $optNode = new Opt_Xml_Element($reader->name);
                 // Parse element attributes, if you manage to get there
                 if ($reader->moveToFirstAttribute()) {
                     do {
                         // "xmlns" special namespace must be handler somehow differently.
                         if ($reader->prefix == 'xmlns') {
                             $ns = str_replace('xmlns:', '', $reader->name);
                             $root->addNamespace($ns, $reader->value);
                             // Let this attribute to appear, if it does not represent an OPT special
                             // namespace
                             if (!$this->_compiler->isNamespace($ns)) {
                                 $optAttribute = new Opt_Xml_Attribute($reader->name, $reader->value);
                                 $optNode->addAttribute($optAttribute);
                             }
                         } else {
                             $optAttribute = new Opt_Xml_Attribute($reader->name, $reader->value);
                             $optNode->addAttribute($optAttribute);
                         }
                     } while ($reader->moveToNextAttribute());
                     $reader->moveToElement();
                 }
                 // Set "rootNode" flag
                 if (!$firstElementMatched) {
                     $optNode->set('rootNode', true);
                     $firstElementMatched = true;
                 }
                 // Set "single" flag
                 if ($reader->isEmptyElement) {
                     $optNode->set('single', true);
                 }
                 $current->appendChild($optNode);
                 break;
             case XMLReader::TEXT:
                 $this->_treeTextCompile($current, $reader->value);
                 break;
             case XMLReader::COMMENT:
                 $optNode = new Opt_Xml_Comment($reader->value);
                 $current->appendChild($optNode);
                 break;
             case XMLReader::CDATA:
                 $cdata = new Opt_Xml_Cdata($reader->value);
                 $cdata->set('cdata', true);
                 if ($current instanceof Opt_Xml_Text) {
                     $current->appendChild($cdata);
                 } else {
                     $text = new Opt_Xml_Text();
                     $text->appendChild($cdata);
                     $current->appendChild($text);
                     $current = $text;
                 }
                 break;
                 /*		case XMLReader::SIGNIFICANT_WHITESPACE:
                 					$cdata = new Opt_Xml_Cdata($reader->value);
                 					$cdata->set('cdata', true);
                 
                 					if($current instanceof Opt_Xml_Text)
                 					{
                 						$current->appendChild($cdata);
                 					}
                 					else
                 					{
                 						$text = new Opt_Xml_Text();
                 						$text->appendChild($cdata);
                 						$current->appendChild($text);
                 						$current = $text;
                 					}
                 					break;
                 		 */
         }
         $depth = $reader->depth;
//.........这里部分代码省略.........
开发者ID:OPL,项目名称:Open-Power-Template,代码行数:101,代码来源:Xml.php

示例11: initFromReader

 /**
  * Initializes this CommonAttributes from an XML reader.
  *
  * @param \XMLReader $xml The reader to use to initialize this object.
  */
 public function initFromReader($xml)
 {
     $empty = $xml->isEmptyElement;
     if ($xml->hasAttributes) {
         $moreAttributes = $xml->moveToFirstAttribute();
         while ($moreAttributes) {
             if (!$this->setKnownAttribute($xml)) {
                 //skip unknown attributes...
             }
             $moreAttributes = $xml->moveToNextAttribute();
         }
     }
     if (!$empty) {
         $xml->read();
         while ($xml->nodeType != \XMLReader::END_ELEMENT) {
             if ($xml->nodeType != \XMLReader::ELEMENT) {
                 //no-op: skip any insignificant whitespace, comments, etc.
             } else {
                 if (!$this->setKnownChildElement($xml)) {
                     $n = $xml->localName;
                     $ns = $xml->namespaceURI;
                     $dom = new \DOMDocument();
                     $nodeFactory = $dom;
                     $dom->formatOutput = true;
                     $e = $nodeFactory->createElementNS($xml->namespaceURI, $xml->localName);
                     $dom->appendChild($e);
                     if ($xml->hasAttributes) {
                         $moreAttributes = $xml->moveToFirstAttribute();
                         while ($moreAttributes) {
                             $e->setAttributeNS($xml->namespaceURI, $xml->localName, $xml->value);
                             $moreAttributes = $xml->moveToNextAttribute();
                         }
                     }
                     $dom = $e;
                     //create any child elements...
                     while ($xml->read() && $xml->nodeType != \XMLReader::END_ELEMENT && $xml->localName != $n && $xml->namespaceURI != $ns) {
                         if ($xml->nodeType == \XMLReader::ELEMENT) {
                             $e = $nodeFactory->createElementNS($xml->namespaceURI, $xml->localName);
                             $dom->appendChild($e);
                             if ($xml->hasAttributes) {
                                 $moreAttributes = $xml->moveToFirstAttribute();
                                 while ($moreAttributes) {
                                     $e->setAttributeNS($xml->namespaceURI, $xml->localName, $xml->value);
                                     $moreAttributes = $xml->moveToNextAttribute();
                                 }
                             }
                             $dom = $e;
                         } else {
                             if ($xml->nodeType == \XMLReader::TEXT) {
                                 $dom->textContent = $xml->value;
                             } else {
                                 if ($xml->nodeType == \XMLReader::END_ELEMENT) {
                                     $dom = $dom->parentNode;
                                 }
                             }
                         }
                     }
                     array_push($this->extensionElements, $nodeFactory);
                 }
             }
             $xml->read();
             //advance the reader.
         }
     }
 }
开发者ID:BRGWeb,项目名称:gedcomx-php,代码行数:70,代码来源:CommonAttributes.php

示例12: readNSinfo

 /**
  * Читает информацию о префиксах и нэймспейсах во внутреннюю структуру
  * @param XMLReader $xr
  */
 protected function readNSinfo($xr)
 {
     $this->xmlnss["_target_ns"] = NULL;
     while ($xr->read()) {
         //первым попадется корневой элемент документа
         if ($xr->nodeType == XMLReader::ELEMENT) {
             if ($xr->hasAttributes && $xr->moveToFirstAttribute()) {
                 do {
                     if ($xr->name == "xmlns") {
                         $this->xmlnss["_default_ns"] = $xr->value;
                     } elseif ($xr->name == "targetNamespace") {
                         $this->xmlnss["_target_ns"] = $xr->value;
                     } elseif (!strncmp($xr->name, "xmlns:", 6)) {
                         $this->xmlnss[substr($xr->name, 6)] = $xr->value;
                     }
                 } while ($xr->moveToNextAttribute());
             }
             //больше ничего неинтересно - выходим
             break;
         }
     }
 }
开发者ID:servandserv,项目名称:happymeal,代码行数:26,代码来源:Request2Xml.php

示例13: moveToFirstAttribute

 public function moveToFirstAttribute()
 {
     return parent::moveToFirstAttribute();
 }
开发者ID:philip,项目名称:phd,代码行数:4,代码来源:Reader.php


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