Beispiel #1
0
 /**
  * Creates a XmlTag object and for each xml tag found in the document, 
  * this function is called recursively to make sure we add all tags and their
  * children
  * 
  * @param XmlTag $tag
  * @return XmlTag
  */
 private function _parse(XmlTag $tag)
 {
     while ($this->_reader->read() && $this->_reader->nodeType !== \XMLReader::END_ELEMENT) {
         if ($this->_reader->nodeType == \XMLReader::ELEMENT) {
             $newTag = new XmlTag();
             $newTag->setTagName($this->_reader->name);
             $newTag->setTagId($this->_tagCounter);
             if ($this->_reader->moveToFirstAttribute()) {
                 $attr = new XmlAttribute();
                 $attr->setName($this->_reader->name);
                 $attr->setValue($this->_reader->value);
                 $newTag->addAttribute($attr);
             }
             $tag->addChild($newTag);
             $this->_tagCounter++;
             $this->_parse($newTag);
         } elseif ($this->_reader->nodeType == \XMLReader::TEXT || $this->_reader->nodeType == \XMLReader::CDATA) {
             $lastTag = $this->_xmlDocument->getTagByTagId($tag->getTagId());
             if (!$lastTag instanceof XmlTag) {
                 // something went very wrong
                 throw new \Exception('Impossible to find tag with id: ', $tag->getId());
             }
             $tag->setValue($this->_reader->value);
         }
     }
     return $tag;
 }