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);
     }
 }
Beispiel #2
0
 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;
 }
Beispiel #3
0
 protected function parseInfo(\XMLReader $xml, InfosAbstract $object)
 {
     // we don't read the name attribute for the module name as in previous jelix version, it has always to be the directory name
     if ($object->type == 'application') {
         $object->name = (string) $xml->getAttribute('name');
     }
     $object->createDate = (string) $xml->getAttribute('createdate');
     $locale = array('label' => $this->locale, 'description' => $this->locale);
     while ($xml->read()) {
         if (\XMLReader::END_ELEMENT == $xml->nodeType && 'info' == $xml->name) {
             break;
         }
         if ($xml->nodeType == \XMLReader::ELEMENT) {
             $property = $xml->name;
             if ('label' == $property || 'description' == $property) {
                 if ($xml->getAttribute('lang') == $locale[$property] || $locale[$property] == '') {
                     $xml->read();
                     $object->{$property} = $xml->value;
                     if ($locale[$property] == '') {
                         // let's mark we readed the element corresponding to the locale
                         $locale[$property] = '__readed__';
                     }
                 }
             } elseif ('author' == $property || 'creator' == $property || 'contributor' == $property) {
                 $person = array();
                 while ($xml->moveToNextAttribute()) {
                     $attrName = $xml->name;
                     $person[$attrName] = $xml->value;
                 }
                 array_push($object->authors, $person);
             } elseif ('licence' == $property) {
                 // we support licence and license, but store always as license
                 while ($xml->moveToNextAttribute()) {
                     $attrProperty = 'license' . ucfirst($xml->name);
                     $object->{$attrProperty} = $xml->value;
                 }
                 $xml->read();
                 $object->license = $xml->value;
             } else {
                 // <version> <license> <copyright> <homepageURL> <updateURL>
                 // read attributes 'date', 'stability' etc ... and store them into versionDate, versionStability
                 while ($xml->moveToNextAttribute()) {
                     $attrProperty = $property . ucfirst($xml->name);
                     $object->{$attrProperty} = $xml->value;
                 }
                 $xml->read();
                 if ($property == 'version') {
                     $object->{$property} = $this->fixVersion($xml->value);
                 } else {
                     $object->{$property} = $xml->value;
                 }
             }
         }
     }
     return $object;
 }
Beispiel #4
0
 protected function parseEntrypoints(\XMLReader $xml, InfosAbstract $object)
 {
     $property = $xml->name;
     while ($xml->read()) {
         if ($xml->nodeType == \XMLReader::END_ELEMENT && 'entrypoints' == $xml->name) {
             break;
         }
         if ($xml->nodeType == \XMLReader::ELEMENT) {
             $id = $config = '';
             $type = 'classic';
             while ($xml->moveToNextAttribute()) {
                 if ($xml->name == 'file') {
                     $id = $xml->value;
                 } else {
                     if ($xml->name == 'config') {
                         $config = $xml->value;
                     } else {
                         if ($xml->name == 'type') {
                             $type = $xml->value;
                         }
                     }
                 }
             }
             if ($id) {
                 if (strpos($id, '.php') === false) {
                     $id .= '.php';
                 }
                 $object->entrypoints[$id] = array('config' => $config, 'file' => $id, 'type' => $type);
             }
         }
     }
 }
 /**
  *  Read the attributes of the current element, and restructure them into a GpxLatLong object
  *
  *  @param   \XMLReader  $xmlReader  The XMLReader object pointing to the current element whose attributes we want to reformat as an object
  *  @return  \GpxReader\GpxLatLong
  **/
 protected function readAttributes(\XMLReader $xmlReader)
 {
     $attributes = new GpxLatLong();
     if ($xmlReader->hasAttributes) {
         while ($xmlReader->moveToNextAttribute()) {
             $this->mapAttributes($xmlReader->name, $xmlReader->value, $attributes);
         }
     }
     return $attributes;
 }
 private function getAttributesFromNode(BasicXmlReader $xml)
 {
     if (!$xml->hasAttributes) {
         return null;
     }
     $attributes = [];
     while ($xml->moveToNextAttribute()) {
         $attributes[$xml->name] = $xml->value;
     }
     return $attributes;
 }
 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));
     }
 }
 protected function parseEntrypoints(XMLReader $xml, $object)
 {
     if (XMLReader::ELEMENT == $xml->nodeType && 'entrypoints' == $xml->name) {
         $property = $xml->name;
         while ($xml->read()) {
             if ($xml->nodeType == XMLReader::END_ELEMENT && 'entrypoints' == $xml->name) {
                 break;
             }
             if ($xml->nodeType == XMLReader::ELEMENT) {
                 $entrypoint = array();
                 while ($xml->moveToNextAttribute()) {
                     $attrName = $xml->name;
                     $entrypoint[$attrName] = $xml->value;
                 }
                 array_push($object->{$property}, $entrypoint);
             }
         }
     }
     return $object;
 }
Beispiel #9
0
 private function initCountries()
 {
     $reader = new XMLReader();
     $reader->open(self::XMLPATH);
     $countries = array();
     while ($reader->read()) {
         if ($reader->name != "iso_3166_entry") {
             continue;
         }
         $country = array();
         while ($reader->moveToNextAttribute()) {
             $country[$reader->name] = $reader->value;
         }
         if (array_key_exists('alpha_2_code', $country)) {
             $countries[$country['alpha_2_code']] = $country;
         }
     }
     $reader->close();
     self::$countries = $countries;
 }
Beispiel #10
0
 protected function parseDependencies(XMLReader $xml, $object)
 {
     if (XMLReader::ELEMENT == $xml->nodeType && 'dependencies' == $xml->name) {
         $property = $xml->name;
         while ($xml->read()) {
             if ($xml->nodeType == XMLReader::END_ELEMENT && 'dependencies' == $xml->name) {
                 break;
             }
             if ($xml->nodeType == XMLReader::ELEMENT) {
                 $dependency = array();
                 $dependency['type'] = $xml->name;
                 while ($xml->moveToNextAttribute()) {
                     $attrName = $xml->name;
                     $dependency[$attrName] = $xml->value;
                 }
                 array_push($object->{$property}, $dependency);
             }
         }
     }
     return $object;
 }
Beispiel #11
0
 protected function _readObject(\XMLReader $xml, $class, $root = false)
 {
     $deConfig = $this->configProvider->getConfig($class)->deserialization;
     if (!isset($deConfig)) {
         throw new \Exception("No config count for {$class}");
     }
     // TODO handle simple value objecty things (XmlValue)
     $ignorableAttributes = array();
     if (!empty($deConfig->subClasses)) {
         if (!empty($deConfig->discriminator)) {
             if (substr($deConfig->discriminator, 0, 1) !== '@') {
                 throw new \Exception("Unsupported discriminator, currently only attributes (denoted with @) are supported. Found: " . $deConfig->discriminator);
             }
             $discrimName = substr($deConfig->discriminator, 1);
             $attrNS = $xml->namespaceURI ? $xml->namespaceURI . ':' : '';
             $ignorableAttributes[$attrNS . $discrimName] = true;
             $discrimValue = $xml->getAttribute($discrimName);
             foreach ($deConfig->subClasses as $subClass) {
                 $subConfig = $this->configProvider->getConfig($subClass)->deserialization;
                 if ($subConfig->discriminatorValue == $discrimValue) {
                     $class = $subClass;
                     $deConfig = $subConfig;
                     break;
                 }
             }
         } elseif ($root && ($xml->name != $deConfig->name || $xml->namespaceURI != $deConfig->namespace)) {
             $matchName = $xml->name;
             $matchNS = $xml->namespaceURI;
             foreach ($deConfig->subClasses as $subClass) {
                 $subConfig = $this->configProvider->getConfig($subClass)->deserialization;
                 if ($subConfig->name == $matchName && $subConfig->namespace == $matchNS) {
                     $class = $subClass;
                     $deConfig = $subConfig;
                     break;
                 }
             }
         }
     }
     $fullName = $xml->namespaceURI . ':' . $xml->name;
     if ($root && ($xml->name != $deConfig->name || $xml->namespaceURI != $deConfig->namespace)) {
         throw new \Exception("Unable to resolve root node for {$fullName}");
     }
     $creatorClass = $class;
     if (!empty($deConfig->factoryClass)) {
         $creatorClass = $deConfig->factoryClass;
     }
     if (!empty($deConfig->factoryMethod)) {
         $creatorMethod = $deConfig->factoryMethod;
         $object = $creatorClass::$creatorMethod();
     } else {
         $object = new $class();
     }
     $seenAttributes = array();
     $seenElements = array();
     $namespace = $xml->namespaceURI;
     if ($xml->hasAttributes) {
         while ($xml->moveToNextAttribute()) {
             $attrNS = $xml->namespaceURI ? $xml->namespaceURI . ':' : (isset($namespace) ? $namespace . ':' : '');
             $fullName = $attrNS . $xml->name;
             if ($xml->name === 'xmlns') {
                 continue;
             }
             if (isset($ignorableAttributes[$fullName])) {
                 continue;
             }
             if (!isset($deConfig->attributes[$fullName])) {
                 throw new \Exception("Unknown attribute found in {$class}: {$fullName}");
             }
             $val = $this->_readAttribute($xml, $deConfig->attributes[$fullName]);
             $this->_setProperty($object, $deConfig->attributes[$fullName]->property, $val);
             $seenAttributes[] = $deConfig->attributes[$fullName]->property->id;
         }
         $xml->moveToElement();
     }
     $knownValues = array();
     if (!$xml->isEmptyElement) {
         while (true) {
             if (!$xml->read()) {
                 throw new \Exception("XML read error");
             }
             switch ($xml->nodeType) {
                 case \XMLReader::ELEMENT:
                     list($propType, $val) = $this->_readElement($xml, $deConfig);
                     $seenElements[] = $propType->id;
                     if (is_array($val)) {
                         if (!isset($knownValues[$propType->id])) {
                             $knownValues[$propType->id] = array($propType, array());
                         }
                         $knownValues[$propType->id][1] = array_merge($knownValues[$propType->id][1], $val);
                     } else {
                         $this->_setProperty($object, $propType, $val);
                     }
                     break;
                 case \XMLReader::END_ELEMENT:
                     break 2;
                 case \XMLReader::WHITESPACE:
                 case \XMLReader::COMMENT:
                 case \XMLReader::SIGNIFICANT_WHITESPACE:
                     break;
                 default:
                     throw new \Exception("XML Parsing error, found unexpected {$xml->nodeType} while parsing for {$class}");
             }
         }
     }
     $notSeenAtts = array_diff($deConfig->requiredAttributes, $seenAttributes);
     $notSeenElements = array_diff($deConfig->requiredElements, $seenElements);
     if (!empty($notSeenAtts) || !empty($notSeenElements)) {
         // TODO fix.
         throw new \Exception("Missing required elements: " . implode(', ', $notSeenElements) . " and attributes: " . implode(',', $notSeenAtts) . "on {$class}");
     }
     foreach ($knownValues as $typeval) {
         list($property, $values) = $typeval;
         $this->_setProperty($object, $property, $values);
     }
     return $object;
 }
 protected function parseRootAttributes(\XMLReader $reader)
 {
     while ($reader->moveToNextAttribute()) {
         $name = $reader->name;
         $value = $reader->value;
         $this->document->setMetadataValue($name, $value);
     }
 }
 /**
  * Process element attributes
  *
  * @param \XMLReader $reader
  * @param \stdClass $tree
  */
 public function processAttributes(&$reader, &$tree)
 {
     $name = $reader->name;
     $node = new \stdClass();
     $node->attr = new \stdClass();
     while ($reader->moveToNextAttribute()) {
         $node->attr->{$name} = $reader->value;
     }
     if (isset($tree->{$name}) && is_a($tree->{$name}, 'ArrayObject')) {
         $lastKey = $tree->{$name}->count() - 1;
         $node->value = $tree->{$name}->offsetGet($lastKey);
         $tree->{$name}->offsetSet($lastKey, $node);
     } else {
         $node->value = isset($tree->{$name}) ? $tree->{$name} : '';
         $tree->{$name} = $node;
     }
 }
Beispiel #14
0
 public function ParseXmlFileData($xml)
 {
     $obReader = new XMLReader();
     $obReader->open($xml, "utf-8");
     if (!$obReader) {
         $this->LAST_ERROR = "Ошибка чтения xml файла";
         return false;
     }
     $arDatum = array();
     $arCatStructs = array();
     $arCatalogs = array();
     $arOrders = array();
     $arSchedules = array();
     $arMasterstats = array();
     while ($obReader->read()) {
         switch ($obReader->nodeType) {
             case XMLReader::ELEMENT:
                 // если users
                 if ($obReader->localName == 'Users') {
                     $obReader->getAttribute("Full");
                     $arParams = array("full" => 1);
                     if ($obReader->getAttribute("Full") == "FALSE") {
                         $arParams = array("full" => 0);
                     }
                     self::ArrayToFile($arParams, 'arParams', $this->sDir . 'params.php');
                     $arUser = array();
                     $iCount = 0;
                     while ($obReader->read()) {
                         if ($obReader->nodeType == XMLReader::ELEMENT) {
                             if ($obReader->localName == 'User') {
                                 $arUser = array();
                                 //приходим в user
                                 $obReader->moveToNextAttribute();
                                 //берем атрибут id
                                 $arUser[$obReader->localName] = $obReader->value;
                                 while ($obReader->read()) {
                                     if ($obReader->nodeType == XMLReader::END_ELEMENT && $obReader->localName == 'User') {
                                         break;
                                     }
                                     if ($obReader->nodeType == XMLReader::ELEMENT) {
                                         //сохраняем значения
                                         $sName = $obReader->localName;
                                         $obReader->read();
                                         if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
                                             $arUser[$sName] = $obReader->value;
                                         }
                                     }
                                 }
                             }
                             //заносим user в массив $arUsers
                             $arDatum[$iCount] = $arUser;
                             $iCount++;
                         }
                     }
                     self::ArrayToFile($arDatum, 'arUsers', $this->sDir . 'users.php');
                     $this->step = $_SESSION['sStep'] = 'addUsers';
                 }
                 /*** Catalog Structure ***/
                 if ($obReader->localName == 'CatalogStructures') {
                     $obReader->getAttribute("Full");
                     $arParams = array("full" => 1);
                     if ($obReader->getAttribute("Full") == "FALSE") {
                         $arParams = array("full" => 0);
                     }
                     self::ArrayToFile($arParams, 'arParams', $this->sDir . 'params.php');
                     $arUser = array();
                     $iCount = 0;
                     while ($obReader->read()) {
                         if ($obReader->nodeType == XMLReader::ELEMENT) {
                             if ($obReader->localName == 'CatalogStructure') {
                                 $arCatStruct = array();
                                 //приходим в user
                                 $obReader->moveToNextAttribute();
                                 //берем атрибут id
                                 $arCatStruct[$obReader->localName] = $obReader->value;
                                 while ($obReader->read()) {
                                     if ($obReader->nodeType == XMLReader::END_ELEMENT && $obReader->localName == 'CatalogStructure') {
                                         break;
                                     }
                                     if ($obReader->nodeType == XMLReader::ELEMENT) {
                                         //сохраняем значения
                                         $sName = $obReader->localName;
                                         $obReader->read();
                                         if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
                                             $arCatStruct[$sName] = $obReader->value;
                                         }
                                     }
                                 }
                             }
                             //заносим user в массив $arCatStructs
                             $arCatStructs[$iCount] = $arCatStruct;
                             $iCount++;
                         }
                     }
                     self::ArrayToFile($arCatStructs, 'arCatStructs', $this->sDir . 'catstruct.php');
                     $this->step = $_SESSION['sStep'] = 'addCatStructs';
                 }
                 /*** Catalog ***/
                 if ($obReader->localName == 'Catalogs') {
                     $obReader->getAttribute("Full");
                     $arParams = array("full" => 1);
                     if ($obReader->getAttribute("Full") == "FALSE") {
                         $arParams = array("full" => 0);
                     }
                     self::ArrayToFile($arParams, 'arParams', $this->sDir . 'params.php');
                     $iCount = 0;
                     while ($obReader->read()) {
                         if ($obReader->nodeType == XMLReader::ELEMENT) {
                             if ($obReader->localName == 'Catalog') {
                                 $arCat = array();
                                 //приходим в user
                                 $obReader->moveToNextAttribute();
                                 //берем атрибут id
                                 $arCat[$obReader->localName] = $obReader->value;
                                 while ($obReader->read()) {
                                     if ($obReader->nodeType == XMLReader::END_ELEMENT && $obReader->localName == 'Catalog') {
                                         break;
                                     }
                                     if ($obReader->nodeType == XMLReader::ELEMENT) {
                                         //сохраняем значения
                                         $sName = $obReader->localName;
                                         $obReader->read();
                                         if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
                                             $arCat[$sName] = $obReader->value;
                                         }
                                     }
                                 }
                             }
                             //заносим user в массив $arCatalogs
                             $arCatalogs[$iCount] = $arCat;
                             $iCount++;
                         }
                     }
                     self::ArrayToFile($arCatalogs, 'arCatalogs', $this->sDir . 'catalogs.php');
                     $this->step = $_SESSION['sStep'] = 'addCatalogs';
                 }
                 /*** Orders ***/
                 if ($obReader->localName == 'Orders') {
                     $obReader->getAttribute("Full");
                     $arParams = array("full" => 1);
                     if ($obReader->getAttribute("Full") == "FALSE") {
                         $arParams = array("full" => 0);
                     }
                     self::ArrayToFile($arParams, 'arParams', $this->sDir . 'params.php');
                     $iCount = 0;
                     while ($obReader->read()) {
                         if ($obReader->nodeType == XMLReader::ELEMENT) {
                             if ($obReader->localName == 'Order') {
                                 $arOrder = array();
                                 //приходим в Order
                                 //$obReader->moveToNextAttribute();
                                 $attr_id = $obReader->getAttribute("id");
                                 if ($attr_id !== NULL) {
                                     $arOrder[$obReader->localName] = $attr_id;
                                     //$obReader->value;
                                 }
                                 //берем атрибут id
                                 while ($obReader->read()) {
                                     if ($obReader->nodeType == 14) {
                                         $obReader->read();
                                     }
                                     if ($obReader->nodeType == XMLReader::END_ELEMENT && $obReader->localName == 'Order') {
                                         break;
                                     }
                                     if ($obReader->nodeType == XMLReader::END_ELEMENT && $obReader->localName == 'OrderItems') {
                                         break;
                                     }
                                     if ($obReader->nodeType == XMLReader::ELEMENT && ($obReader->localName == 'ClientId' || $obReader->localName == 'Date')) {
                                         //сохраняем значения
                                         $sName = $obReader->localName;
                                         $obReader->read();
                                         if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
                                             $arOrder[$sName] = $obReader->value;
                                         }
                                         $obReader->read();
                                         $obReader->read();
                                         $obReader->read();
                                         //echo $obReader->localName.' - '.$obReader->value;
                                         if ($obReader->nodeType == XMLReader::ELEMENT && ($obReader->localName == 'ClientId' || $obReader->localName == 'Date')) {
                                             //сохраняем значения
                                             $sName = $obReader->localName;
                                             $obReader->read();
                                             if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
                                                 $arOrder[$sName] = $obReader->value;
                                             }
                                             $obReader->read();
                                             $obReader->read();
                                         }
                                     }
                                     if ($obReader->nodeType == XMLReader::ELEMENT && $obReader->localName == 'OrderItems') {
                                         $arOrder['OrderItems'] = array();
                                     }
                                     $arOrderItem = array();
                                     while ($obReader->read()) {
                                         if ($obReader->nodeType == XMLReader::END_ELEMENT && $obReader->localName == 'OrderItem') {
                                             break;
                                         }
                                         if ($obReader->nodeType == XMLReader::ELEMENT && ($obReader->localName == 'CatalogId' || $obReader->localName == 'MasterId' || $obReader->localName == 'Quantity' || $obReader->localName == 'Price')) {
                                             //сохраняем значения
                                             $sName = $obReader->localName;
                                             $obReader->read();
                                             if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
                                                 $arOrderItem[$sName] = $obReader->value;
                                             }
                                         }
                                     }
                                     $arOrder['OrderItems'][] = $arOrderItem;
                                 }
                             }
                             //заносим user в массив $arCatalogs
                             $arOrders[$iCount] = $arOrder;
                             $iCount++;
                         }
                     }
                     self::ArrayToFile($arOrders, 'arOrders', $this->sDir . 'orders.php');
                     $this->step = $_SESSION['sStep'] = 'addOrders';
                 }
                 /*** Shedule ***/
                 if ($obReader->localName == 'Schedules') {
                     $obReader->getAttribute("Full");
                     $arParams = array("full" => 1);
                     if ($obReader->getAttribute("Full") == "FALSE") {
                         $arParams = array("full" => 0);
                     }
                     self::ArrayToFile($arParams, 'arParams', $this->sDir . 'params.php');
                     $iCount = 0;
                     while ($obReader->read()) {
                         if ($obReader->nodeType == XMLReader::ELEMENT) {
                             if ($obReader->localName == 'Schedule') {
                                 $arSchedule = array();
                                 //приходим в Schedule
                                 //$obReader->moveToNextAttribute();
                                 $attr_id = $obReader->getAttribute("id");
                                 if ($attr_id !== NULL) {
                                     $arSchedule[$obReader->localName] = $attr_id;
                                     //$obReader->value;
                                 }
                                 //берем атрибут id
                                 while ($obReader->read()) {
                                     if ($obReader->nodeType == 14) {
                                         $obReader->read();
                                     }
                                     if ($obReader->nodeType == XMLReader::END_ELEMENT && $obReader->localName == 'Schedule') {
                                         break;
                                     }
                                     if ($obReader->nodeType == XMLReader::END_ELEMENT && $obReader->localName == 'OrderItems') {
                                         break;
                                     }
                                     if ($obReader->nodeType == XMLReader::ELEMENT && $obReader->localName == 'Date') {
                                         //сохраняем значения
                                         $sName = $obReader->localName;
                                         $obReader->read();
                                         if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
                                             $arSchedule[$sName] = $obReader->value;
                                         }
                                         $obReader->read();
                                         $obReader->read();
                                         $obReader->read();
                                     }
                                     if ($obReader->nodeType == XMLReader::ELEMENT && $obReader->localName == 'ClientId') {
                                         //сохраняем значения
                                         $sName = $obReader->localName;
                                         $obReader->read();
                                         if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
                                             $arSchedule[$sName] = $obReader->value;
                                         }
                                         $obReader->read();
                                         $obReader->read();
                                         $obReader->read();
                                     }
                                     if ($obReader->nodeType == XMLReader::ELEMENT && $obReader->localName == 'MasterId') {
                                         //сохраняем значения
                                         $sName = $obReader->localName;
                                         $obReader->read();
                                         if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
                                             $arSchedule[$sName] = $obReader->value;
                                         }
                                         $obReader->read();
                                         $obReader->read();
                                         $obReader->read();
                                     }
                                     if ($obReader->nodeType == XMLReader::ELEMENT && $obReader->localName == 'DateTimeFrom') {
                                         //сохраняем значения
                                         $sName = $obReader->localName;
                                         $obReader->read();
                                         if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
                                             $arSchedule[$sName] = $obReader->value;
                                         }
                                         $obReader->read();
                                         $obReader->read();
                                         $obReader->read();
                                     }
                                     if ($obReader->nodeType == XMLReader::ELEMENT && $obReader->localName == 'DateTimeTo') {
                                         //сохраняем значения
                                         $sName = $obReader->localName;
                                         $obReader->read();
                                         if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
                                             $arSchedule[$sName] = $obReader->value;
                                         }
                                     }
                                     if ($obReader->nodeType == XMLReader::ELEMENT && $obReader->localName == 'OrderItems') {
                                         $arSchedule['OrderItems'] = array();
                                     }
                                     $arOrderItem = array();
                                     while ($obReader->read()) {
                                         if ($obReader->nodeType == XMLReader::END_ELEMENT && $obReader->localName == 'OrderItem') {
                                             break;
                                         }
                                         if ($obReader->nodeType == XMLReader::ELEMENT && ($obReader->localName == 'CatalogId' || $obReader->localName == 'MasterId' || $obReader->localName == 'Price')) {
                                             //сохраняем значения
                                             $sName = $obReader->localName;
                                             $obReader->read();
                                             if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
                                                 $arOrderItem[$sName] = $obReader->value;
                                             }
                                         }
                                     }
                                     $arSchedule['OrderItems'][] = $arOrderItem;
                                 }
                             }
                             //заносим user в массив $arCatalogs
                             $arSchedules[$iCount] = $arSchedule;
                             $iCount++;
                         }
                     }
                     self::ArrayToFile($arSchedules, 'arSchedules', $this->sDir . 'schedules.php');
                     $this->step = $_SESSION['sStep'] = 'addSchedules';
                 }
                 /*** Masterstat ***/
                 if ($obReader->localName == 'Masterstats') {
                     $obReader->getAttribute("Full");
                     $arParams = array("full" => 1);
                     if ($obReader->getAttribute("Full") == "FALSE") {
                         $arParams = array("full" => 0);
                     }
                     self::ArrayToFile($arParams, 'arParams', $this->sDir . 'params.php');
                     $iCount = 0;
                     while ($obReader->read()) {
                         if ($obReader->nodeType == XMLReader::ELEMENT) {
                             if ($obReader->localName == 'Masterstat') {
                                 $arMasterstat = array();
                                 //приходим в user
                                 $obReader->moveToNextAttribute();
                                 //берем атрибут id
                                 $arMasterstat[$obReader->localName] = $obReader->value;
                                 while ($obReader->read()) {
                                     if ($obReader->nodeType == XMLReader::END_ELEMENT && $obReader->localName == 'Masterstat') {
                                         break;
                                     }
                                     if ($obReader->nodeType == XMLReader::ELEMENT) {
                                         //сохраняем значения
                                         $sName = $obReader->localName;
                                         $obReader->read();
                                         if ($obReader->nodeType !== XMLReader::END_ELEMENT) {
                                             $arMasterstat[$sName] = $obReader->value;
                                         }
                                     }
                                 }
                             }
                             //заносим user в массив $arUsers
                             $arMasterstats[$iCount] = $arMasterstat;
                             $iCount++;
                         }
                     }
                     self::ArrayToFile($arMasterstats, 'arMasterstats', $this->sDir . 'masterstats.php');
                     $this->step = $_SESSION['sStep'] = 'addMasterstats';
                 }
                 break;
         }
     }
     /* if (empty($arUsers)) {
            $this->LAST_ERROR = "Ошибка парсинга xml файла пользователей";
            return false;
        } */
     return true;
 }
Beispiel #15
0
 /**
  * Process a node from the XML Map
  * It is permitted for the XML to just define one or more tables without fields (when the 'use headers' option is used)
  *
  * Note: Calls itself recursively to process a tree
  *
  * @return bool returns true if all fine else false
  */
 private function _getXmlNode($node_content, $current_record, $xml_path)
 {
     $jinput = JFactory::getApplication()->input;
     $csvilog = $jinput->get('csvilog', null, null);
     $current_node = '';
     $xml_schema = new XMLReader();
     /**
      * Add a wrapper to make the XML viable and ensure that self closing tags contain a space before the '/>'
      * The XML may still be invalid but that's down to what the user entered
      */
     $node_content = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<da_root>" . $node_content . '</da_root>';
     $xml_schema->XML($node_content);
     // XML file to table map is valid XML - construct the arrays used in file extraction
     $use_read = true;
     // The XML could only be validated against a DTD if the syntax of the XML used for the map is made more complex
     $validate_xml = false;
     if ($validate_xml == true) {
         // Note: When the DTD is external, the property value must be set before the first read()
         $xml_schema->setParserProperty(XMLReader::VALIDATE, true);
     }
     while ($use_read ? $xml_schema->read() : $xml_schema->next()) {
         // Validation checking disabled because a DTD (or RELAX NG) schema is required.
         if ($validate_xml == true) {
             if ($xml_schema->isValid() == false) {
                 $xml_schema->close();
                 return false;
             }
         }
         // Default to a reading a single node in the next loop
         $use_read = true;
         // Ignore any node associated with the root
         if ($xml_schema->name == 'da_root') {
             continue;
         }
         // Process start elements
         if ($xml_schema->nodeType == XMLReader::ELEMENT) {
             $self_closing = $xml_schema->isEmptyElement;
             // Ready to add a new node - but only if the last node was closed
             if (!empty($current_node)) {
                 $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_XML_NODE_UNCLOSED', $current_node));
                 return false;
             }
             // A new node was found - Check whether this is a new record type
             if (empty($current_record)) {
                 // New record type
                 // Check for a self-closing node
                 $self_closing = $xml_schema->isEmptyElement;
                 $current_record = strtolower($xml_schema->name);
                 $this->_xml_records[] = strtolower($current_record);
                 // Store any attributes
                 while ($xml_schema->moveToNextAttribute()) {
                     // Note1: $xml_schema->hasValue only indicates whether the element can have a value, not whether it does
                     // Note2: empty($xml_schema->value) always return true, regardless of the actual value
                     $value = $xml_schema->value;
                     if (!empty($value)) {
                         if ($this->_isXmlFieldNameValid($xml_schema->value)) {
                             $this->_xml_schema[$current_record]['attrs'][strtolower($xml_schema->name)] = trim($xml_schema->value);
                         } else {
                             $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_XML_FILE_MAP_NO_REFERENCE', $xml_schema->value));
                             $xml_schema->close();
                             return false;
                         }
                     }
                 }
                 // Check for a self-closing node
                 if ($self_closing == true) {
                     $current_record = '';
                 }
             } else {
                 // New field type
                 $current_node = strtolower($xml_schema->name);
                 $current_path = $this->_getXmlNodePath($xml_path, $current_node);
                 // Store any attributes
                 while ($xml_schema->moveToNextAttribute()) {
                     // Note1: $xml_schema->hasValue only indicates whether the element can have a value, not whether it does
                     // Note2: empty($xml_schema->value) always return true, regardless of the actual value
                     $value = $xml_schema->value;
                     if (!empty($value)) {
                         if ($this->_isXmlFieldNameValid($xml_schema->value)) {
                             $this->_xml_schema[$current_record]['nodes'][$current_path]['attrs'][strtolower($xml_schema->name)] = trim($xml_schema->value);
                         } else {
                             $csvilog->AddStats('incorrect', JText::_('COM_CSVI_XML_FILE_MAP_NO_REFERENCE', $xml_schema->value));
                             $xml_schema->close();
                             return false;
                         }
                     }
                 }
                 $sub_node_content = $xml_schema->readInnerXML();
                 // Check whether there are any lower level nodes
                 if (strstr($sub_node_content, '<') === false) {
                     /**
                      * Content has no embedded nodes - Assume a field name
                      * Note: An empty node gives a blank field name which indicates an unwanted node
                      * that is being mapped to prevent errors when processing the file
                      */
                     if ($this->_isXmlFieldNameValid($sub_node_content)) {
                         $this->_xml_schema[$current_record]['nodes'][$current_path]['field'] = trim($sub_node_content);
                     } else {
                         $this->_xml_schema[$current_record]['nodes'][$current_path]['field'] = '';
                     }
                 } else {
                     // There are embedded nodes - go down another level
                     // Indicate a 'group' node by storing an empty field name
                     $this->_xml_schema[$current_record]['nodes'][$current_path]['field'] = '';
                     // Push the node name to the path stack
                     $this->_pushXmlNodePath($xml_path, $current_node);
                     if ($this->_getXmlNode($sub_node_content, $current_record, $xml_path) == false) {
                         $xml_schema->close();
                         return false;
                     }
                     // At the next read, skip to the next node at this level
                     $use_read = false;
                     // Close the node
                     $current_node = '';
                     // Pop the last item off the path stack
                     $this->_popXmlNodePath($xml_path);
                 }
                 // Check for a self-closing node
                 if ($self_closing == true) {
                     $current_node = '';
                 }
             }
         } else {
             if ($xml_schema->nodeType == XMLReader::END_ELEMENT) {
                 // End of node found
                 // Check for end of record
                 if (!empty($current_record) && strtolower($xml_schema->name) == $current_record) {
                     // End of record detected
                     $current_record = '';
                 } else {
                     if (!empty($current_node) && strtolower($xml_schema->name) == $current_node) {
                         // End of current node detected
                         $current_node = '';
                     }
                 }
             }
         }
     }
     $xml_schema->close();
     // Node not terminated
     if (!empty($current_node)) {
         $csvilog->AddStats('incorrect', JText::sprintf('COM_CSVI_XML_NODE_NOT_CLOSED', $current_node));
         return false;
     }
     if (empty($this->_xml_records)) {
         $csvilog->AddStats('incorrect', JText::_('COM_CSVI_XML_NO_RECORDS_DEFINED'));
         return false;
     }
     return true;
 }
Beispiel #16
0
 /**
  * Get all of the attributes for an XMLReader's current node
  * @param $r XMLReader
  * @return array of attributes
  */
 private function getAttributesArray(XMLReader $r)
 {
     $attrs = [];
     while ($r->moveToNextAttribute()) {
         if ($r->namespaceURI === 'http://www.w3.org/2000/xmlns/') {
             // XMLReader treats xmlns attributes as normal
             // attributes, while xml_parse doesn't
             continue;
         }
         $name = $this->expandNS($r->name, $r->namespaceURI);
         $attrs[$name] = $r->value;
     }
     return $attrs;
 }
Beispiel #17
0
 /**
  * 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;
 }
 /**
  * Method for recursive processing of xml dom nodes.
  *
  * @param XMLReader $xml
  * @param string    $path
  *
  * @return array|string
  */
 protected function xml_to_array(XMLReader $xml, $path = '')
 {
     $data = null;
     while ($xml->read()) {
         switch ($xml->nodeType) {
             case XMLReader::ELEMENT:
                 if ($data === null) {
                     $data = [];
                 } elseif (!is_array($data)) {
                     throw new Exception(_s('Invalid tag "%1$s": %2$s.', $path, _s('unexpected text "%1$s"', trim($data))));
                 }
                 $node_name = $xml->name;
                 $sub_path = $path . '/' . $node_name;
                 if (array_key_exists($node_name, $data)) {
                     $node_name .= count($data);
                     $sub_path .= '(' . count($data) . ')';
                 }
                 /*
                  * A special case for 1.8 import where attributes are still used attributes must be added to the
                  * array as if they where child elements.
                  */
                 if ($xml->hasAttributes) {
                     while ($xml->moveToNextAttribute()) {
                         $data[$node_name][$xml->name] = $xml->value;
                     }
                     /*
                      * We assume that an element with attributes always contains child elements, not a text node
                      * works for 1.8 XML.
                      */
                     $child_data = $this->xml_to_array($xml, $sub_path);
                     if (is_array($child_data)) {
                         foreach ($child_data as $child_node_name => $child_node_value) {
                             if (array_key_exists($child_node_name, $data[$node_name])) {
                                 $child_node_name .= count($data[$node_name]);
                             }
                             $data[$node_name][$child_node_name] = $child_node_value;
                         }
                     } elseif ($child_data !== '') {
                         throw new Exception(_s('Invalid tag "%1$s": %2$s.', $sub_path, _s('unexpected text "%1$s"', trim($child_data))));
                     }
                 } else {
                     $data[$node_name] = $xml->isEmptyElement ? '' : $this->xml_to_array($xml, $sub_path);
                 }
                 break;
             case XMLReader::TEXT:
                 if ($data === null) {
                     $data = $xml->value;
                 } elseif (is_array($data)) {
                     throw new Exception(_s('Invalid tag "%1$s": %2$s.', $path, _s('unexpected text "%1$s"', trim($xml->value))));
                 }
                 break;
             case XMLReader::END_ELEMENT:
                 /*
                  * For tags with empty value: <dns></dns>.
                  */
                 if ($data === null) {
                     $data = '';
                 }
                 return $data;
         }
     }
     return $data;
 }
Beispiel #19
0
 /**
  * Traverse XML tree
  *
  * Traverses the XML tree and calls the learnAutomaton() method for each 
  * element, with its child element nodes.
  * 
  * @param DOMNode $root 
  * @return void
  */
 protected function traverse(XMLReader $reader, $path = array())
 {
     $contents = array();
     $whitespace = array();
     $children = array();
     $attributes = array();
     // Learn attributes for this element
     while ($reader->moveToNextAttribute()) {
         $attributes[$reader->name] = $reader->value;
     }
     $reader->moveToElement();
     // If this is an empty element, do not traverse, but return
     // immediately.
     if ($reader->nodeType === XMLReader::ELEMENT && $reader->isEmptyElement) {
         $element = $this->getType($path);
         $this->learnAutomaton($element, $children);
         $this->learnSimpleType($element, $contents);
         $this->learnAttributes($element, $attributes);
         return;
     }
     // Traverse child elements.
     while ($reader->read()) {
         switch ($reader->nodeType) {
             case XMLReader::ELEMENT:
                 // Opening tag
                 $child = array('namespace' => $reader->namespaceURI, 'name' => $reader->localName, 'parents' => $path);
                 $children[] = $child;
                 $childPath = array_merge($path, array($child));
                 // If we are in the document root, add the child as root
                 // element.
                 if (count($path) === 0) {
                     $this->rootElements[$child['name']] = $this->inferenceType($childPath);
                 }
                 $this->traverse($reader, $childPath);
                 break;
             case XMLReader::END_ELEMENT:
                 // Closing tag
                 $element = $this->getType($path);
                 if (!count($children)) {
                     // Significant whitespace seems only significant if
                     // there are children, but there is still some
                     // whitespace.
                     $contents = array_merge($contents, $whitespace);
                 }
                 $this->learnAutomaton($element, $children);
                 $this->learnSimpleType($element, $contents);
                 $this->learnAttributes($element, $attributes);
                 return;
             case XMLReader::TEXT:
             case XMLReader::CDATA:
                 // Text content
                 $contents[] = $reader->value;
                 break;
             case XMLReader::SIGNIFICANT_WHITESPACE:
                 $whitespace[] = $reader->value;
                 break;
         }
     }
 }
Beispiel #20
0
<?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===
Beispiel #21
0
 private function lookupNamespaces(\XMLReader $reader)
 {
     $aNS = array();
     while ($reader->read()) {
         switch ($reader->nodeType) {
             // case \XMLReader::NONE : break;
             case \XMLReader::ELEMENT:
                 $aNS[$reader->prefix] = $reader->namespaceURI;
                 if ($reader->hasAttributes) {
                     while ($reader->moveToNextAttribute()) {
                         $aNS[$reader->prefix] = $reader->namespaceURI;
                     }
                 }
                 if (!$reader->isEmptyElement) {
                     $aNS = array_merge($aNS, $this->lookupNamespaces($reader));
                 }
                 break;
                 // case \XMLReader::ATTRIBUTE : break;
                 // case \XMLReader::TEXT : break;
             // case \XMLReader::ATTRIBUTE : break;
             // case \XMLReader::TEXT : break;
             case \XMLReader::END_ELEMENT:
                 //dspf($reader->expand(new \XML_Element)); break 2;
                 // case \XMLReader::XML_DECLARATION : break;
         }
     }
     return $aNS;
 }
Beispiel #22
0
 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()) {
             $this->error_code = $error->code;
             $this->error_string = $error->message;
             $this->current_line = $error->line;
             $this->current_column = $error->column;
             return false;
         } else {
             return true;
         }
     }
 }
Beispiel #23
0
 private function getAttributes(XMLReader $xml, $attrsLists = 'all')
 {
     $attrs = array();
     if (is_array($attrsLists)) {
         foreach ($attrsLists as $attr) {
             $attrs[$attr] = $xml->getAttribute($attr);
         }
     } else {
         if ($attrsLists == 'all') {
             while ($xml->moveToNextAttribute()) {
                 $attrs[$xml->name] = $xml->value;
             }
         }
     }
     // return the reader to the original Element
     $xml->moveToElement();
     return $attrs;
 }
Beispiel #24
0
 /**
  * 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;
     }
     // Error checking
     $errors = libxml_get_errors();
     if (sizeof($errors) > 0) {
         libxml_clear_errors();
         foreach ($errors as $error) {
             echo $error->message . ' (' . $error->line . ')<br/>';
         }
     }
     return $root;
 }
Beispiel #25
0
/* rdfReader */
/* parses data, creates RTF */
/* XMLReader tutorial - http://www.ibm.com/developerworks/xml/library/x-xmlphp2.html */
$url = str_replace("getSingleStuff.xq", "", $appurl) . $doc . '_ead.xml?_xsl=styles/ead2rdf.xsl';
$reader = new XMLReader();
$reader->open($url);
$empty = false;
while ($reader->read()) {
    if ($reader->isEmptyElement) {
        $empty = true;
    }
    if ($reader->nodeType == XMLReader::ELEMENT) {
        echo '<' . $reader->name;
        if ($reader->attributeCount > 0) {
            while ($reader->moveToNextAttribute()) {
                echo " " . $reader->name . '="' . $reader->value . '"';
            }
        }
        if ($empty) {
            echo " />";
            $empty = false;
        } else {
            echo '>';
        }
    } else {
        if ($reader->nodeType == XMLReader::END_ELEMENT) {
            echo '</' . $reader->name . '>';
        } else {
            echo $reader->value;
        }
Beispiel #26
0
 /**
  * Creates an array from a given xml file
  *
  * @param String $FileName
  * @return Array
  */
 public function LoadFormXML($FileName)
 {
     $Form = array();
     $xml = new XMLReader();
     $xml->open($FileName);
     while ($xml->read()) {
         if ($xml->name == 'form' && $xml->nodeType == XMLReader::ELEMENT) {
             RDD::Log('Found Formtag', TRACE, 1203);
             // This will create the $Form Array
             while ($xml->moveToNextAttribute()) {
                 if ($xml->name == 'name' || $xml->name == 'submitvalue') {
                     $Form[$xml->name] = T($xml->value);
                 } else {
                     $Form[$xml->name] = $xml->value;
                 }
             }
             $Form['elements'] = array();
             while ($xml->read()) {
                 // The $EmptyElement and $EmtyData stuff is for the 2 different cases with <element></element> and <element />
                 $EmptyElement = false;
                 if ($xml->name == 'element' && $xml->nodeType == XMLReader::ELEMENT) {
                     if ($xml->isEmptyElement) {
                         $EmptyElement = true;
                     }
                     $NewElement = array();
                     $Validators = array();
                     $Transforms = array();
                     $Prepares = array();
                     $Datas = array();
                     $Values = array();
                     $EmptyValue;
                     $DataCounter = 0;
                     $ValueCounter = 0;
                     $dataName = $DataCounter;
                     $valuename = $DataCounter;
                     while ($xml->moveToNextAttribute()) {
                         if ($xml->name == 'name' || substr($xml->name, 0, 4) == 'text') {
                             $NewElement[$xml->name] = T($xml->value);
                         } else {
                             $NewElement[$xml->name] = $xml->value;
                         }
                     }
                     $Form['elements'][$NewElement['id']] = $NewElement;
                     if (!$EmptyElement) {
                         while ($xml->read()) {
                             // This part is for the parsing of the data elements within an "element" element
                             $EmptyData = false;
                             if ($xml->name == 'data' && $xml->nodeType == XMLReader::ELEMENT) {
                                 if ($xml->isEmptyElement) {
                                     $EmptyData = true;
                                 }
                                 $Joins = array();
                                 $NewData = array();
                                 while ($xml->moveToNextAttribute()) {
                                     $NewData[$xml->name] = $xml->value;
                                 }
                                 if (isset($NewData['id'])) {
                                     $dataName = $NewData['id'];
                                 } else {
                                     $dataName = $DataCounter;
                                 }
                                 $Form['elements'][$NewElement['id']]['datas'][$dataName] = $NewData;
                                 if (!$EmptyData) {
                                     // This will create the join array
                                     while ($xml->read()) {
                                         if ($xml->name == 'join' && $xml->nodeType == XMLReader::ELEMENT) {
                                             $NewJoin = array();
                                             while ($xml->moveToNextAttribute()) {
                                                 if ($xml->name == 'addempty') {
                                                     $NewJoin[$xml->name] = T($xml->value);
                                                 } else {
                                                     $NewJoin[$xml->name] = $xml->value;
                                                 }
                                             }
                                             $Joins[] = $NewJoin;
                                         } elseif ($xml->name == 'data' && $xml->nodeType == XMLReader::END_ELEMENT) {
                                             break;
                                         }
                                     }
                                     // This will add the join array (if it exists) to the $form array
                                     if (!empty($Joins)) {
                                         $Form['elements'][$NewElement['id']]['datas'][$dataName]['joins'] = $Joins;
                                     }
                                 }
                                 // This is for the counter of data element, it only counts if no id is given
                                 if (!isset($NewData['id'])) {
                                     $DataCounter++;
                                 }
                             }
                             if ($xml->name == 'value' && $xml->nodeType == XMLReader::ELEMENT) {
                                 $NewValue = array();
                                 while ($xml->moveToNextAttribute()) {
                                     $NewValue[$xml->name] = $xml->value;
                                 }
                                 if (isset($NewValue['id'])) {
                                     $ValueName = $NewValue['id'];
                                 } else {
                                     $ValueName = $ValueCounter;
                                 }
                                 $Form['elements'][$NewElement['id']]['values'][$ValueName] = $NewValue;
                                 // This is for the counter ofvalue element, it only counts if no id is given
                                 if (!isset($NewValue['id'])) {
                                     $ValueCounter++;
                                 }
                             }
                             if ($xml->name == 'validator' && $xml->nodeType == XMLReader::ELEMENT) {
                                 $NewValidator = array();
                                 while ($xml->moveToNextAttribute()) {
                                     $NewValidator[$xml->name] = $xml->value;
                                 }
                                 $Validators[] = $NewValidator;
                             } elseif ($xml->name == 'prepare' && $xml->nodeType == XMLReader::ELEMENT) {
                                 $NewPrepare = array();
                                 while ($xml->moveToNextAttribute()) {
                                     $NewPrepare[$xml->name] = $xml->value;
                                 }
                                 $Prepares[] = $NewPrepare;
                             } elseif ($xml->name == 'transform' && $xml->nodeType == XMLReader::ELEMENT) {
                                 $NewTransform = array();
                                 while ($xml->moveToNextAttribute()) {
                                     $NewTransform[$xml->name] = $xml->value;
                                 }
                                 $Transforms[] = $NewTransform;
                             } elseif ($xml->name == 'element' && $xml->nodeType == XMLReader::END_ELEMENT) {
                                 break;
                             }
                         }
                         if (!empty($Validators)) {
                             $Form['elements'][$NewElement['id']]['validators'] = $Validators;
                         }
                         if (!empty($Transforms)) {
                             $Form['elements'][$NewElement['id']]['transforms'] = $Transforms;
                         }
                         if (!empty($Prepares)) {
                             $Form['elements'][$NewElement['id']]['prepares'] = $Prepares;
                         }
                         if (!empty($Datas)) {
                             $Form['elements'][$NewElement['id']]['datas'] = $Datas;
                         }
                     }
                 }
             }
             return $Form;
         }
     }
 }
 /**
  * Parse XML file
  *
  * Parse the given XML into arbitXmlNode objects using the XMLReader class.
  *
  * @param string $xmlFile
  * @return arbitXmlNode
  */
 protected static function parseXml($xmlFile)
 {
     $reader = new XMLReader();
     // Use custom error handling to suppress warnings and errors during
     // parsing.
     $libXmlErrors = libxml_use_internal_errors(true);
     // Try to open configuration file, and throw parsing exception if
     // something fails.
     $errors = array();
     // Just open, errors will not occure before actually reading.
     $reader->open($xmlFile);
     // Current node, processed. Start with a reference to th root node.
     $current = $root = new arbitXml();
     // Stack of parents for the current node. We store this list, because
     // we do not want to store a parent node reference in the nodes, as
     // this breaks with var_export'ing those structures.
     $parents = array($root);
     // Start processing the XML document
     //
     // The read method may issue warning, even if
     // libxml_use_internal_errors was set to true. That sucks, and we need
     // to use the @ here...
     while (@$reader->read()) {
         switch ($reader->nodeType) {
             case XMLReader::ELEMENT:
                 // A new element, which results in a new configuration node as
                 // a child of the current node
                 //
                 // Get name of new element
                 $nodeName = $reader->name;
                 // We create a new object, so append the current node as
                 // future parent node to the parent stack.
                 array_push($parents, $current);
                 // Create new child and reference node as current working
                 // node
                 $current = $current->{$nodeName} = new arbitXmlNode();
                 // After reading the elements we need to know about this
                 // for further progressing
                 $emptyElement = $reader->isEmptyElement;
                 // Process elements attributes, if available
                 if ($reader->hasAttributes) {
                     // Read all attributes and store their values in the
                     // current configuration node
                     while ($reader->moveToNextAttribute()) {
                         $current[$reader->name] = $reader->value;
                     }
                 }
                 if (!$emptyElement) {
                     // We only break for non empty elements.
                     //
                     // For empty elements the element may also be counted
                     // as a closing tag, so that we want also process the
                     // next case statement.
                     break;
                 }
             case XMLReader::END_ELEMENT:
                 // At the end of a element set the current pointer back to its
                 // parent
                 //
                 // Pop new current node from parents stack
                 $current = array_pop($parents);
                 break;
             case XMLReader::TEXT:
             case XMLReader::CDATA:
                 // Text and CData node are added as node content.
                 //
                 // Append string, in case several text or Cdata nodes exist
                 // in one node
                 $current->setContent((string) $current . $reader->value);
                 break;
                 // Everything else can be ignored for now..
         }
     }
     // Check if errors occured while reading configuration
     if (count($errors = libxml_get_errors())) {
         // Reset libxml error handling to old state
         libxml_use_internal_errors($libXmlErrors);
         libxml_clear_errors();
         throw new arbitXmlParserException($xmlFile, $errors);
     }
     // Reset libxml error handling to old state
     libxml_use_internal_errors($libXmlErrors);
     return $root->skipRoot();
 }
 protected function readDataBlock()
 {
     $v4b43b0aee35624cd95b910189b3dc231 = new XMLReader();
     $v4b43b0aee35624cd95b910189b3dc231->open($this->file_path);
     $v2245023265ae4cf87d02c8b6ba991139 = mainConfiguration::getInstance();
     $vf7c163939469a0b7becb4e4e6a94efac = $v2245023265ae4cf87d02c8b6ba991139->includeParam('system.kernel') . 'subsystems/import/schemes/' . $this->type . '.xsd';
     if (is_file($vf7c163939469a0b7becb4e4e6a94efac)) {
         $v4b43b0aee35624cd95b910189b3dc231->setSchema($vf7c163939469a0b7becb4e4e6a94efac);
     }
     $v9a09b4dfda82e3e665e31092d1c3ec8d = new DomDocument("1.0", "utf-8");
     $v07214c6750d983a32e0a33da225c4efd = array("Группа", "Товар", "Предложение");
     $vc00d122cde678a9551cae41dc45a40b7 = array('ОписаниеГрупп');
     $v95723b5e620e47cf613462b9f293282a = 0;
     $v4757fe07fd492a8be0ea6a760d683d6e = 0;
     $v5f0b6ebc4bea10285ba2b8a6ce78b863 = $v9a09b4dfda82e3e665e31092d1c3ec8d;
     $v7aa28ed115707345d0274032757e8991 = $v4b43b0aee35624cd95b910189b3dc231->read();
     while ($v7aa28ed115707345d0274032757e8991) {
         switch ($v4b43b0aee35624cd95b910189b3dc231->nodeType) {
             case XMLReader::ELEMENT:
                 if (in_array($v4b43b0aee35624cd95b910189b3dc231->name, $vc00d122cde678a9551cae41dc45a40b7)) {
                     $v7aa28ed115707345d0274032757e8991 = $v4b43b0aee35624cd95b910189b3dc231->next();
                     continue;
                 }
                 if (in_array($v4b43b0aee35624cd95b910189b3dc231->name, $v07214c6750d983a32e0a33da225c4efd)) {
                     if ($v4757fe07fd492a8be0ea6a760d683d6e++ < $this->offset) {
                         $v7aa28ed115707345d0274032757e8991 = $v4b43b0aee35624cd95b910189b3dc231->next();
                         continue 2;
                     }
                     if ($v95723b5e620e47cf613462b9f293282a + 1 > $this->block_size) {
                         if ($v4b43b0aee35624cd95b910189b3dc231->name == "Предложение") {
                             $vd60db28d94d538bbb249dcc7f2273ab1 = DOMDocument::loadXML($v4b43b0aee35624cd95b910189b3dc231->readOuterXML());
                             if ($this->__getOffersCompare($v9a09b4dfda82e3e665e31092d1c3ec8d, $vd60db28d94d538bbb249dcc7f2273ab1, $v95723b5e620e47cf613462b9f293282a)) {
                                 break 2;
                             }
                         } else {
                             break 2;
                         }
                     }
                     $v95723b5e620e47cf613462b9f293282a++;
                 }
                 $v65c10911d8b8591219a21ebacf46da01 = $v9a09b4dfda82e3e665e31092d1c3ec8d->createElement($v4b43b0aee35624cd95b910189b3dc231->name, $v4b43b0aee35624cd95b910189b3dc231->value);
                 $v5f0b6ebc4bea10285ba2b8a6ce78b863->appendChild($v65c10911d8b8591219a21ebacf46da01);
                 if (!$v4b43b0aee35624cd95b910189b3dc231->isEmptyElement) {
                     $v5f0b6ebc4bea10285ba2b8a6ce78b863 = $v65c10911d8b8591219a21ebacf46da01;
                 }
                 if ($v4b43b0aee35624cd95b910189b3dc231->attributeCount) {
                     while ($v4b43b0aee35624cd95b910189b3dc231->moveToNextAttribute()) {
                         $v815be97df65d6c4b510cd07189c5347a = $v9a09b4dfda82e3e665e31092d1c3ec8d->createAttribute($v4b43b0aee35624cd95b910189b3dc231->name);
                         $v815be97df65d6c4b510cd07189c5347a->appendChild($v9a09b4dfda82e3e665e31092d1c3ec8d->createTextNode($v4b43b0aee35624cd95b910189b3dc231->value));
                         $v65c10911d8b8591219a21ebacf46da01->appendChild($v815be97df65d6c4b510cd07189c5347a);
                     }
                 }
                 $v3f02ab347aeca12e013036ce82046c38 = $this->__getNodePath($v5f0b6ebc4bea10285ba2b8a6ce78b863);
                 if ($v3f02ab347aeca12e013036ce82046c38 == "КоммерческаяИнформация/Классификатор/Группы") {
                     $v556216bbe3169f8132fe2b1683164988 = $v4b43b0aee35624cd95b910189b3dc231->readOuterXML();
                     $v1471e4e05a4db95d353cc867fe317314 = new DOMDocument('1.0', 'utf-8');
                     $v1471e4e05a4db95d353cc867fe317314->loadXML($v556216bbe3169f8132fe2b1683164988);
                     $v076933917d4df1df9aeaf50e0d25297b = $v1471e4e05a4db95d353cc867fe317314->getElementsByTagName('Группа');
                     foreach ($v076933917d4df1df9aeaf50e0d25297b as $vdb0f6f37ebeb6ea09489124345af2a45) {
                         if ($v4757fe07fd492a8be0ea6a760d683d6e++ < $this->offset) {
                             continue;
                         }
                         if ($v95723b5e620e47cf613462b9f293282a + 1 > $this->block_size) {
                             break;
                         }
                         $this->__collectGroup($v9a09b4dfda82e3e665e31092d1c3ec8d, $v65c10911d8b8591219a21ebacf46da01, $vdb0f6f37ebeb6ea09489124345af2a45);
                         $v95723b5e620e47cf613462b9f293282a++;
                     }
                     $v5f0b6ebc4bea10285ba2b8a6ce78b863 = $v5f0b6ebc4bea10285ba2b8a6ce78b863->parentNode;
                     $v7aa28ed115707345d0274032757e8991 = $v4b43b0aee35624cd95b910189b3dc231->next();
                     continue 2;
                 }
                 break;
             case XMLReader::END_ELEMENT:
                 $v5f0b6ebc4bea10285ba2b8a6ce78b863 = $v5f0b6ebc4bea10285ba2b8a6ce78b863->parentNode;
                 break;
             case XMLReader::ATTRIBUTE:
                 $v815be97df65d6c4b510cd07189c5347a = $v9a09b4dfda82e3e665e31092d1c3ec8d->createAttribute($v4b43b0aee35624cd95b910189b3dc231->name);
                 $v815be97df65d6c4b510cd07189c5347a->appendChild($v9a09b4dfda82e3e665e31092d1c3ec8d->createTextNode($v4b43b0aee35624cd95b910189b3dc231->value));
                 $v5f0b6ebc4bea10285ba2b8a6ce78b863->appendChild($v815be97df65d6c4b510cd07189c5347a);
                 break;
             case XMLReader::TEXT:
                 $vc7824f3d4d5f7b2f22d034758c1e9454 = $v9a09b4dfda82e3e665e31092d1c3ec8d->createTextNode($v4b43b0aee35624cd95b910189b3dc231->value);
                 $v5f0b6ebc4bea10285ba2b8a6ce78b863->appendChild($vc7824f3d4d5f7b2f22d034758c1e9454);
                 break;
             case XMLReader::CDATA:
                 $vd9ef6bda8fb69f1c7e277bd1c2cd21d1 = $v9a09b4dfda82e3e665e31092d1c3ec8d->createCDATASection($v4b43b0aee35624cd95b910189b3dc231->value);
                 $v5f0b6ebc4bea10285ba2b8a6ce78b863->appendChild($vd9ef6bda8fb69f1c7e277bd1c2cd21d1);
                 break;
             case XMLReader::NONE:
             default:
         }
         $v7aa28ed115707345d0274032757e8991 = $v4b43b0aee35624cd95b910189b3dc231->read();
     }
     $this->offset += $v95723b5e620e47cf613462b9f293282a;
     if (!$v7aa28ed115707345d0274032757e8991) {
         $this->complete = true;
     }
     return $v9a09b4dfda82e3e665e31092d1c3ec8d;
 }
Beispiel #29
0
 public function _get_conferences()
 {
     $bbconf = array();
     foreach (Doctrine_Query::create()->select("n.number,e.name,e.conference_id")->from("Number n,Conference e")->where("n.class_type='ConferenceNumber'")->andWhere("n.foreign_id=e.conference_id")->orderBy("e.name")->execute(array(), Doctrine::HYDRATE_SCALAR) as $conference) {
         $bbconf["conference_" . $conference["e_conference_id"]] = $conference;
     }
     $clid = array();
     foreach (Doctrine::getTable('Device')->findAll() as $ext) {
         if (array_key_exists('callerid', $ext['plugins']) && array_key_exists('internal_name', $ext['plugins']['callerid']) && array_key_exists('internal_number', $ext['plugins']['callerid'])) {
             if (array_key_exists('sip', $ext['plugins']) && array_key_exists('username', $ext['plugins']['sip'])) {
                 $clid[$ext['plugins']['sip']['username']] = array('name' => $ext['plugins']['callerid']['internal_name'], 'ext' => $ext['plugins']['callerid']['internal_number']);
             }
         }
     }
     $esl = new EslManager();
     $res = $esl->api("conference xml_list");
     $xml = new XMLReader();
     $xml->xml($esl->getResponse($res));
     $conferences = array();
     $path = array();
     while ($xml->read()) {
         if ($xml->nodeType == XMLReader::ELEMENT) {
             array_unshift($path, $xml->name);
             if ($xml->name == 'conference') {
                 $conferences[] = array();
                 end($conferences);
                 $conf =& $conferences[key($conferences)];
                 $current =& $conferences[key($conferences)];
                 $conf['members'] = array();
             } elseif ($xml->name == 'member') {
                 $key = count($conf['members']);
                 $conf['members'][$key] = array();
                 $member =& $conf['members'][$key];
                 $current =& $conf['members'][$key];
             }
             if ($xml->hasAttributes) {
                 while ($xml->moveToNextAttribute()) {
                     $current[$xml->name] = $xml->value;
                     if ($xml->name == 'name' && array_key_exists($xml->value, $bbconf)) {
                         $current['bluebox'] = $bbconf[$xml->value];
                     }
                 }
             }
         } elseif ($xml->nodeType == XMLReader::END_ELEMENT) {
             array_shift($path);
         } elseif ($xml->nodeType == XMLReader::TEXT) {
             $current[$path[0]] = $xml->value;
             if ($path[0] == "caller_id_number" && array_key_exists($xml->value, $clid)) {
                 $current['clid'] = $clid[$xml->value];
             }
         }
     }
     return $conferences;
 }
 /**
  * Parse XML feed
  *
  * @param string
  * @param string
  */
 private function _parse($data, $charset = 'UTF-8')
 {
     /* There's a bug in certain versions of libxml2 which silently strips &lt; &gt; etc */
     static $isNotBuggy = null;
     if ($isNotBuggy === null) {
         $_check = xml_parser_create();
         xml_parse_into_struct($_check, '<ips>&amp;</ips>', $values);
         xml_parser_free($_check);
         $isNotBuggy = isset($values[0]['value']);
     }
     /* Ok to use libxml? */
     if ($isNotBuggy) {
         $xml_parser = xml_parser_create($charset);
         xml_set_element_handler($xml_parser, array(&$this, "_parseStartElement"), array(&$this, "_parseEndElement"));
         xml_set_character_data_handler($xml_parser, array(&$this, "_parseCharacterData"));
         if (!xml_parse($xml_parser, $data)) {
             $this->errors[] = sprintf("XML error: %s at line %d", xml_error_string(xml_get_error_code($xml_parser)), xml_get_current_line_number($xml_parser));
         }
         @xml_parser_free($xml_parser);
     } else {
         libxml_clear_errors();
         $xml = new XMLReader();
         $xml->xml($data);
         while (@$xml->read()) {
             switch ($xml->nodeType) {
                 case constant('XMLReader::END_ELEMENT'):
                     if ($xml->namespaceURI !== '') {
                         $tag = $xml->namespaceURI . ' ' . $xml->localName;
                     } else {
                         $tag = $xml->localName;
                     }
                     $this->_parseEndElement(null, $tag);
                     break;
                 case constant('XMLReader::ELEMENT'):
                     $empty = $xml->isEmptyElement;
                     if ($xml->namespaceURI !== '') {
                         $tag = $xml->namespaceURI . ' ' . $xml->localName;
                     } else {
                         $tag = $xml->localName;
                     }
                     $attr = array();
                     while ($xml->moveToNextAttribute()) {
                         if ($xml->namespaceURI !== '') {
                             $attrName = $xml->namespaceURI . ' ' . $xml->localName;
                         } else {
                             $attrName = $xml->localName;
                         }
                         $attr[$attrName] = $xml->value;
                     }
                     $this->_parseStartElement(null, $tag, $attr);
                     if ($empty) {
                         $this->_parseEndElement(null, $tag);
                     }
                     break;
                 case constant('XMLReader::TEXT'):
                 case constant('XMLReader::CDATA'):
                     $this->_parseCharacterData(null, $xml->value);
                     break;
             }
         }
         if ($error = libxml_get_last_error()) {
             $this->errors[] = sprintf("XML error: %s at line %d", $error->message, $error->line);
             return false;
         } else {
             return true;
         }
     }
 }