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


PHP XMLParser::parse方法代码示例

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


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

示例1: testEmails

 function testEmails($locale, $referenceLocale)
 {
     import('install.Installer');
     // Bring in data dir
     $errors = array();
     $xmlParser = new XMLParser();
     $referenceEmails =& $xmlParser->parse(INSTALLER_DATA_DIR . "/data/locale/{$referenceLocale}/email_templates_data.xml");
     $emails =& $xmlParser->parse(INSTALLER_DATA_DIR . "/data/locale/{$locale}/email_templates_data.xml");
     $emailsTable =& $emails->getChildByName('table');
     $referenceEmailsTable =& $referenceEmails->getChildByName('table');
     $matchedReferenceEmails = array();
     // Pass 1: For all translated emails, check that they match
     // against reference translations.
     for ($emailIndex = 0; ($email =& $emailsTable->getChildByName('row', $emailIndex)) !== null; $emailIndex++) {
         // Extract the fields from the email to be tested.
         $fields = $this->extractFields($email);
         // Locate the reference email and extract its fields.
         for ($referenceEmailIndex = 0; ($referenceEmail =& $referenceEmailsTable->getChildByName('row', $referenceEmailIndex)) !== null; $referenceEmailIndex++) {
             $referenceFields = $this->extractFields($referenceEmail);
             if ($referenceFields['email_key'] == $fields['email_key']) {
                 break;
             }
         }
         // Check if a matching reference email was found.
         if (!isset($referenceEmail) || $referenceEmail === null) {
             $errors[EMAIL_ERROR_EXTRA_EMAIL][] = array('key' => $fields['email_key']);
             continue;
         }
         // We've successfully found a matching reference email.
         // Compare it against the translation.
         $bodyParams = $this->getParameterNames($fields['body']);
         $referenceBodyParams = $this->getParameterNames($referenceFields['body']);
         if ($bodyParams !== $referenceBodyParams) {
             $errors[EMAIL_ERROR_DIFFERING_PARAMS][] = array('key' => $fields['email_key'], 'mismatch' => array_diff($bodyParams, $referenceBodyParams));
         }
         $subjectParams = $this->getParameterNames($fields['subject']);
         $referenceSubjectParams = $this->getParameterNames($referenceFields['subject']);
         if ($subjectParams !== $referenceSubjectParams) {
             $errors[EMAIL_ERROR_DIFFERING_PARAMS][] = array('key' => $fields['email_key'], 'mismatch' => array_diff($subjectParams, $referenceSubjectParams));
         }
         $matchedReferenceEmails[] = $fields['email_key'];
         unset($email);
         unset($referenceEmail);
     }
     // Pass 2: Make sure that there are no missing translations.
     for ($referenceEmailIndex = 0; ($referenceEmail =& $referenceEmailsTable->getChildByName('row', $referenceEmailIndex)) !== null; $referenceEmailIndex++) {
         // Extract the fields from the email to be tested.
         $referenceFields = $this->extractFields($referenceEmail);
         if (!in_array($referenceFields['email_key'], $matchedReferenceEmails)) {
             $errors[EMAIL_ERROR_MISSING_EMAIL][] = array('key' => $referenceFields['email_key']);
         }
     }
     $this->displayEmailErrors($locale, $errors);
 }
开发者ID:jalperin,项目名称:harvester,代码行数:54,代码来源:localeCheck.php

示例2: scan

    /**
     * Scan the plugin registry for custom roles, tasks and commands,
     * and register them as existing.
     */
    function scan()
    {
        static $scanned = false;
        if ($scanned) {
            return;
        }

        $scanned = true;
        $parser = new XMLParser;
        $schemapath = Main::getDataPath();
        if (!file_exists(Main::getDataPath() . '/channel-1.0.xsd')) {
            $schemapath = realpath(__DIR__ . '/../../data');
        }

        $roleschema    = $schemapath . '/customrole-2.0.xsd';
        $taskschema    = $schemapath . '/customtask-2.0.xsd';
        $commandschema = $schemapath . '/customcommand-2.0.xsd';

        try {
            foreach (Config::current()->channelregistry as $channel) {
                foreach ($this->listPackages($channel->name) as $package) {
                    $chan = $channel->name;
                    $files = $this->info($package, $chan, 'installedfiles');
                    // each package may only have 1 role, task or command
                    foreach ($files as $path => $info) {
                        switch ($info['role']) {
                            case 'customrole' :
                                $roleinfo = $parser->parse($path, $roleschema);
                                $roleinfo = $roleinfo['role'];
                                static::makeAutoloader($roleinfo, 'role');
                                Installer\Role::registerCustomRole($roleinfo);
                                continue 2;
                            case 'customtask' :
                                $taskinfo = $parser->parse($path, $taskschema);
                                $taskinfo = $taskinfo['task'];
                                static::makeAutoloader($taskinfo, 'task');
                                Task\Common::registerCustomTask($taskinfo);
                                continue 2;
                            case 'customcommand' :
                                $commands = $parser->parse($path, $commandschema);
                                $this->addCommand($commands['commands']['command']);
                                continue 2;
                        }
                    }
                }
            }
        } catch (\Exception $e) {
            Logger::log(0, 'Unable to add all custom roles/tasks/commands: ' . $e);
        }
    }
开发者ID:naderman,项目名称:PEAR2_Pyrus,代码行数:54,代码来源:PluginRegistry.php

示例3: installSettings

 /**
  * Install conference settings from an XML file.
  * @param $id int ID of scheduled conference/conference for settings to apply to
  * @param $filename string Name of XML file to parse and install
  * @param $paramArray array Optional parameters for variable replacement in settings
  */
 function installSettings($id, $filename, $paramArray = array())
 {
     $xmlParser = new XMLParser();
     $tree = $xmlParser->parse($filename);
     if (!$tree) {
         $xmlParser->destroy();
         return false;
     }
     foreach ($tree->getChildren() as $setting) {
         $nameNode =& $setting->getChildByName('name');
         $valueNode =& $setting->getChildByName('value');
         if (isset($nameNode) && isset($valueNode)) {
             $type = $setting->getAttribute('type');
             $isLocaleField = $setting->getAttribute('locale');
             $name =& $nameNode->getValue();
             if ($type == 'date') {
                 $value = strtotime($valueNode->getValue());
             } elseif ($type == 'object') {
                 $arrayNode =& $valueNode->getChildByName('array');
                 $value = $this->_buildObject($arrayNode, $paramArray);
             } else {
                 $value = $this->_performReplacement($valueNode->getValue(), $paramArray);
             }
             // Replace translate calls with translated content
             $this->updateSetting($id, $name, $isLocaleField ? array(Locale::getLocale() => $value) : $value, $type, $isLocaleField);
         }
     }
     $xmlParser->destroy();
 }
开发者ID:ramonsodoma,项目名称:ocs,代码行数:35,代码来源:SettingsDAO.inc.php

示例4: XMLParser

 /**
  * Parse an XML file with the specified handler and return data in an object.
  * @see xml.XMLParser::parse()
  * @param $handler reference to the handler to use with the parser.
  */
 function &parseWithHandler($file, &$handler)
 {
     $parser = new XMLParser();
     $parser->setHandler($handler);
     $data =& $parser->parse($file);
     $parser->destroy();
     return $data;
 }
开发者ID:JovanyJeff,项目名称:hrp,代码行数:13,代码来源:XMLDAO.inc.php

示例5: XMLParser

 /**
  * Parse an RT version XML file.
  * @param $file string path to the XML file
  * @return RTVersion
  */
 function &parse($file)
 {
     $parser = new XMLParser();
     $tree = $parser->parse($file);
     $parser->destroy();
     $version = false;
     if ($tree !== false) {
         $version =& $this->parseVersion($tree);
     }
     $tree->destroy();
     return $version;
 }
开发者ID:master3395,项目名称:CBPPlatform,代码行数:17,代码来源:RTXMLParser.inc.php

示例6: fetchData

 /**
  * Parse and return DHL tracking details.
  *
  * @inheritdoc
  */
 public function fetchData($trackingNumber)
 {
     $link = 'http://track.dhl-usa.com/TrackByNbr.asp?ShipmentNumber=' . $trackingNumber;
     $html = $this->fetchUrl($link);
     if (!preg_match_all('#<input type="hidden" name="hdnXML([^"]+)" value="([^"]+)"/>#', $html, $matches, PREG_SET_ORDER)) {
         // XML tracking details not found
         return false;
     }
     $stats = array();
     $locations = array();
     $xml = '';
     foreach ($matches as $match) {
         $xml .= $match[2];
     }
     $xml = html_entity_decode($xml);
     $parser = new XMLParser();
     $obj = $parser->parse($xml);
     if (!isset($obj->track->trackshipments->shipment->result->code->data) && $obj->track->trackshipments->shipment->result->code->data != 1) {
         // XML document could not be parsed
         return false;
     }
     $stats['service'] = isset($obj->track->trackshipments->shipment->service->desc->data) ? $obj->track->trackshipments->shipment->service->desc->data : '';
     $stats['departure'] = isset($obj->track->trackshipments->shipment->pickup->date->data) ? $obj->track->trackshipments->shipment->pickup->date->data : '';
     $stats['destination'] = isset($obj->track->trackshipments->shipment->destinationdescr->location->data) ? $obj->track->trackshipments->shipment->destinationdescr->location->data : '';
     $stats['arrival'] = isset($obj->track->trackshipments->shipment->delivery->date->data) ? $obj->track->trackshipments->shipment->delivery->date->data : '';
     if (isset($obj->track->trackshipments->shipment->trackinghistory->status)) {
         if (!is_array($obj->track->trackshipments->shipment->trackinghistory->status)) {
             $obj->track->trackshipments->shipment->trackinghistory->status = array($obj->track->trackshipments->shipment->trackinghistory->status);
         }
         foreach ($obj->track->trackshipments->shipment->trackinghistory->status as $history) {
             $row = array();
             $row['location'] = $history->location->city->data . ', ';
             if (isset($history->location->state->data) && !empty($history->location->state->data)) {
                 $row['location'] .= $history->location->state->data . ', ';
             }
             if (isset($history->location->country->data) && !empty($history->location->country->data)) {
                 $row['location'] .= $history->location->country->data;
             }
             $row['location'] = rtrim($row['location'], ', ');
             $row['time'] = $history->date->data . ' ' . $history->time->data;
             $row['status'] = $history->statusdesc->data;
             $locations[] = $row;
             if (!isset($stats['status'])) {
                 $stats['status'] = $history->statusdesc->data;
             }
             if (!isset($stats['last_location'])) {
                 $stats['last_location'] = $row['location'];
             }
         }
     }
     return array('details' => $stats, 'locations' => $locations);
 }
开发者ID:RandomArray,项目名称:php-parcel-tracker,代码行数:57,代码来源:dhl.class.php

示例7: check

 /**
  * Cast a given value
  *
  * Error codes returned are:
  * <ul>
  *   <li>invalid_chars - if input contains characters not allowed for XML</li>
  *   <li>not_well_formed - if input cannot be parsed to XML</li>
  * </ul>
  *
  * @param   array value
  * @return  string error or array on success
  */
 public function check($value)
 {
     foreach ($value as $v) {
         if (strlen($v) > strcspn($v, Node::XML_ILLEGAL_CHARS)) {
             return 'invalid_chars';
         }
         try {
             $p = new XMLParser();
             $p->parse('<doc>' . $v . '</doc>');
         } catch (XMLFormatException $e) {
             return 'not_well_formed';
         }
     }
     return NULL;
 }
开发者ID:melogamepay,项目名称:xp-framework,代码行数:27,代码来源:WellformedXMLChecker.class.php

示例8: doupdate

 function doupdate()
 {
     include_once HDWIKI_ROOT . '/lib/xmlparser.class.php';
     $sendversion = base64_encode(serialize(array('v' => HDWIKI_VERSION, 'r' => HDWIKI_RELEASE, 'c' => WIKI_CHARSET, 'u' => WIKI_URL)));
     $xmlfile = "http://kaiyuan.hudong.com/update.php?v={$sendversion}";
     $xmlparser = new XMLParser();
     $xmlnav = $xmlparser->parse($xmlfile);
     $isupdate = $xmlnav[0]['child'][0]['content'];
     $version = $xmlnav[0]['child'][1]['content'];
     $release = $xmlnav[0]['child'][2]['content'];
     $url = $xmlnav[0]['child'][3]['content'];
     $description = $xmlnav[0]['child'][4]['content'];
     $json = '{"isupdate":"' . $isupdate . '","version":"' . $version . '","release":"' . $release . '","url":"' . $url . '","description":"' . $description . '"}';
     echo $json;
 }
开发者ID:meiwenhui,项目名称:hdwiki,代码行数:15,代码来源:admin_main.php

示例9: format

 /**
  * format - prune the registry based on xml config
  *
  * @param string    XMLpath
  * @param Registry  registry
  *
  * @return array
  */
 public static function format($xmlFilePath, $uri, Registry $registry)
 {
     $xml = file_get_contents($xmlFilePath);
     $xmlParser = new XMLParser();
     $params = $xmlParser->parse($xml, $uri, 'outputParam');
     unset($xmlParser);
     $output = array();
     if (count($params) < 1) {
         if (self::PARANOID_MODE) {
             error_log('XML is missing CherryPicker configs for ' . $uri);
             throw new XMLNodeNotConfiguredException('XML is missing CherryPicker configs for ' . $uri);
         }
         //not paranoid? ok - dump the whole registry to the user
         foreach ($registry->toArray() as $key => $value) {
             $output[self::trimNamespacing($key)] = $registry->{$key};
         }
         return $output;
     }
     foreach ($params as $key) {
         self::formatValue($key, $output, $registry);
     }
     return $output;
 }
开发者ID:dmeikle,项目名称:gossamerCMS-application,代码行数:31,代码来源:OutputCherryPicker.php

示例10: fetchUpdates

 /**
  * Fetches the statuses of the circuit boards from the database.
  * @throws Exception If a query fails to execute.
  */
 public function fetchUpdates()
 {
     $soap = new SoapClientWrapper();
     $messages = $soap->getNewMessages();
     $database = new DatabaseWrapper();
     $database->connect(DB_NAME);
     foreach ($messages as $message) {
         $xmlParser = new XMLParser($message);
         $xmlParser->parse();
         $parsedMessage = $xmlParser->getParsedData();
         $validator = new SMSValidator($parsedMessage);
         try {
             $msisdn = $validator->validateMSISDN();
             $status = $validator->validateStatus();
             $information = $database->queryBoardInformation($msisdn);
             $update = new CircuitBoard($information, $status);
             $database->updateBoardStatus($msisdn, $status);
             $this->model->addUpdate($update);
         } catch (Exception $e) {
             continue;
         }
     }
 }
开发者ID:jianzi0307,项目名称:m2m-sms,代码行数:27,代码来源:UpdatesController.php

示例11: _getRates

 private function _getRates($response)
 {
     $doc = new \XMLDocument();
     $xp = new \XMLParser();
     $xp->setDocument($doc);
     $xp->parse($response);
     $doc = $xp->getDocument();
     $rates = array();
     $results = array();
     if (is_object($doc->root)) {
         $root = $doc->getRoot();
         if ($root->getElementByName('ratesAndServicesResponse')) {
             $service_rates = $root->getElementByName('ratesAndServicesResponse');
             $shipment = $service_rates->getElementsByName('product');
             $currencies = Registry::get('currencies');
             if (!empty($currencies['CAD'])) {
                 for ($i = 0; $i < count($shipment); $i++) {
                     $id = $shipment[$i]->getAttribute("id");
                     if (!empty($id) && $id > 0) {
                         $rates[$id] = array('rate' => floatval($shipment[$i]->getValueByPath("rate")) * $currencies['CAD']['coefficient']);
                         if ($shipment[$i]->getValueByPath("deliveryDate") != '') {
                             $rates[$id]['delivery_time'] = $shipment[$i]->getValueByPath("deliveryDate");
                         }
                         unset($id);
                     }
                 }
                 $results['cost'] = $rates;
             } else {
                 $results['error'] = __('canada_post_activation_error');
             }
         } elseif ($root->getElementByName('error')) {
             $results['error'] = $root->getValueByPath('/error/statusMessage');
         }
     }
     return $results;
 }
开发者ID:askzap,项目名称:ultimate,代码行数:36,代码来源:Can.php

示例12: parseTasks

 /**
  * Parse and execute the scheduled tasks in the specified file.
  * @param $file string
  */
 function parseTasks($file)
 {
     $xmlParser = new XMLParser();
     $tree = $xmlParser->parse($file);
     if (!$tree) {
         $xmlParser->destroy();
         printf("Unable to parse file \"%s\"!\n", $file);
         exit(1);
     }
     foreach ($tree->getChildren() as $task) {
         $className = $task->getAttribute('class');
         $frequency = $task->getChildByName('frequency');
         if (isset($frequency)) {
             $canExecute = ScheduledTaskHelper::checkFrequency($className, $frequency);
         } else {
             // Always execute if no frequency is specified
             $canExecute = true;
         }
         if ($canExecute) {
             $this->executeTask($className, ScheduledTaskHelper::getTaskArgs($task));
         }
     }
     $xmlParser->destroy();
 }
开发者ID:farhanabbas1983,项目名称:ojs-1,代码行数:28,代码来源:ScheduledTaskTool.inc.php

示例13: parseData

 /**
  * Parse an XML data file into SQL statements.
  * @param $file string path to the XML file to parse
  * @return array the array of SQL statements parsed
  */
 function parseData($file)
 {
     $this->sql = array();
     $parser = new XMLParser();
     $tree = $parser->parse($file);
     if (!$tree) {
         return array();
     }
     $allTables = $this->dbconn->MetaTables();
     foreach ($tree->getChildren() as $type) {
         switch ($type->getName()) {
             case 'table':
                 $fieldDefaultValues = array();
                 // Match table element
                 foreach ($type->getChildren() as $row) {
                     switch ($row->getName()) {
                         case 'field_default':
                             // Match a default field element
                             list($fieldName, $value) = $this->_getFieldData($row);
                             $fieldDefaultValues[$fieldName] = $value;
                             break;
                         case 'row':
                             // Match a row element
                             $fieldValues = array();
                             foreach ($row->getChildren() as $field) {
                                 // Get the field names and values for this INSERT
                                 list($fieldName, $value) = $this->_getFieldData($field);
                                 $fieldValues[$fieldName] = $value;
                             }
                             $fieldValues = array_merge($fieldDefaultValues, $fieldValues);
                             if (count($fieldValues) > 0) {
                                 $this->sql[] = sprintf('INSERT INTO %s (%s) VALUES (%s)', $type->getAttribute('name'), join(', ', array_keys($fieldValues)), join(', ', array_values($fieldValues)));
                             }
                             break;
                         default:
                             assert(false);
                     }
                 }
                 break;
             case 'sql':
                 // Match sql element (set of SQL queries)
                 foreach ($type->getChildren() as $child) {
                     switch ($child->getName()) {
                         case 'drop':
                             if (!isset($dbdict)) {
                                 $dbdict = @NewDataDictionary($this->dbconn);
                             }
                             $table = $child->getAttribute('table');
                             $column = $child->getAttribute('column');
                             if ($column) {
                                 // NOT PORTABLE; do not use this
                                 $this->sql[] = $dbdict->DropColumnSql($table, $column);
                             } else {
                                 $this->sql[] = $dbdict->DropTableSQL($table);
                             }
                             break;
                         case 'rename':
                             if (!isset($dbdict)) {
                                 $dbdict = @NewDataDictionary($this->dbconn);
                             }
                             $table = $child->getAttribute('table');
                             $column = $child->getAttribute('column');
                             $to = $child->getAttribute('to');
                             if ($column) {
                                 // Make sure the target column does not yet exist.
                                 // This is to guarantee idempotence of upgrade scripts.
                                 $run = false;
                                 if (in_array($table, $allTables)) {
                                     $columns =& $this->dbconn->MetaColumns($table, true);
                                     if (!isset($columns[strtoupper($to)])) {
                                         // Only run if the column has not yet been
                                         // renamed.
                                         $run = true;
                                     }
                                 } else {
                                     // If the target table does not exist then
                                     // we assume that another rename entry will still
                                     // rename it and we should run after it.
                                     $run = true;
                                 }
                                 if ($run) {
                                     $colId = strtoupper($column);
                                     $flds = '';
                                     if (isset($columns[$colId])) {
                                         $col = $columns[$colId];
                                         if ($col->max_length == "-1") {
                                             $max_length = '';
                                         } else {
                                             $max_length = $col->max_length;
                                         }
                                         $fld = array('NAME' => $col->name, 'TYPE' => $dbdict->MetaType($col), 'SIZE' => $max_length);
                                         if ($col->primary_key) {
                                             $fld['KEY'] = 'KEY';
                                         }
                                         if ($col->auto_increment) {
//.........这里部分代码省略.........
开发者ID:PublishingWithoutWalls,项目名称:pkp-lib,代码行数:101,代码来源:DBDataXMLParser.inc.php

示例14: getEmailTemplates

 function getEmailTemplates($locale)
 {
     $files = TranslatorAction::getEmailFileMap($locale);
     $returner = array();
     foreach ($files as $templateFile => $templateDataFile) {
         $xmlParser = new XMLParser();
         $data = null;
         if (file_exists($templateDataFile)) {
             $data =& $xmlParser->parse($templateDataFile);
         }
         if ($data) {
             foreach ($data->getChildren() as $emailNode) {
                 $returner[$emailNode->getAttribute('key')] = array('subject' => $emailNode->getChildValue('subject'), 'body' => $emailNode->getChildValue('body'), 'description' => $emailNode->getChildValue('description'), 'templateFile' => $templateFile, 'templateDataFile' => $templateDataFile);
             }
         }
         unset($xmlParser, $data);
     }
     return $returner;
 }
开发者ID:EreminDm,项目名称:water-cao,代码行数:19,代码来源:TranslatorAction.inc.php

示例15: fn_arb_get_error

function fn_arb_get_error($result, $request_type)
{
    $doc = new XMLDocument();
    $xp = new XMLParser();
    $xp->setDocument($doc);
    $xp->parse($result);
    $doc = $xp->getDocument();
    $return = array();
    if (is_object($doc->root)) {
        $root = $doc->getRoot();
        $shipments = $root->getElementsByName($request_type);
        if ($shipments) {
            for ($k = 0; $k < count($shipments); $k++) {
                $faults = $shipments[$k]->getElementByName("Faults");
                if (!empty($faults)) {
                    $fault = $faults->getElementsByName("Fault");
                    for ($i = 0; $i < count($fault); $i++) {
                        $return[] = $fault[$i]->getValueByPath("/Desc") . ($fault[$i]->getElementByName("Context") ? ' (' . trim($fault[$i]->getValueByPath("/Context")) . ')' : '');
                    }
                }
            }
        }
    }
    return implode(' / ', $return);
}
开发者ID:diedsmiling,项目名称:busenika,代码行数:25,代码来源:dhl.php


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