本文整理汇总了PHP中XMLParser类的典型用法代码示例。如果您正苦于以下问题:PHP XMLParser类的具体用法?PHP XMLParser怎么用?PHP XMLParser使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了XMLParser类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _loadXML
/**
* ModuleOpenImmo::_loadXML
*
* Returns an array containing the xml data
* @param fileName
* @returns array
**/
public function _loadXML($fileName = NULL)
{
// load xml file
$sXML = NULL;
$sXML = @file_get_contents(TL_ROOT . DIRECTORY_SEPARATOR . $fileName);
if (!empty($sXML)) {
// check for known namespaces
$knownNameSpace = false;
foreach ($this->aAllowedNamespaces as $nameSpace) {
if (strpos($sXML, '<' . $nameSpace . ':') !== FALSE) {
$knownNameSpace = true;
// strip namespace from xml
$sXML = str_replace(array('<' . $nameSpace . ':', '</' . $nameSpace . ':'), array('<', '</'), $sXML);
}
}
// no of the known namespaces given? NOT VALID!
if (!$knownNameSpace) {
return false;
}
// parse our xml into an array
$oXML = NULL;
$oXML = new XMLParser();
$aXML = array();
$aXML = $oXML->xmlToArray($sXML);
// strip our root node and return xml
if (!empty($aXML)) {
$rootNodeName = array_keys($aXML);
$rootNodeName = $rootNodeName[0];
$aXML = $aXML[$rootNodeName][0];
return $aXML;
}
}
return false;
}
示例2: thor_build_display_values
function thor_build_display_values()
{
$form = new entity($this->form_id);
$form->get_values();
if ($form->get_value('type') != id_of('form'))
{
trigger_error('the thor viewer was passed an invalid id ('.$form_id.') - it must be passed the ID of a reason form entity');
}
else
{
$form_xml_obj = new XMLParser($form->get_value('thor_content'));
$form_xml_obj->Parse();
$display_values = array();
foreach ($form_xml_obj->document->tagChildren as $k=>$v)
{
$tagname = is_object($v) ? $v->tagName : '';
if (method_exists($this, '_build_display_'.$tagname))
{
$build_function = '_build_display_'.$tagname;
$display_values = array_merge($display_values, $this->$build_function($v));
}
}
}
foreach ($this->extra_fields as $field_name)
{
$display_values[$field_name]['label'] = prettify_string($field_name);
$display_values[$field_name]['type'] = 'text';
}
$this->_display_values = (isset($display_values)) ? $display_values : array();
}
示例3: parseEmails
/**
* Parse into structures the XML contents of an email data file.
* @param $contents string
* @return array
*/
function parseEmails($contents)
{
$parser = new XMLParser();
$result = $parser->parseTextStruct($contents, array('email_text', 'subject', 'body'));
$parser->destroy();
return $result;
}
示例4: ask_eve_central
/**
* Query EVE Central's XML feed.
*/
function ask_eve_central($item_id)
{
file_put_contents(KB_CACHEDIR . '/evecentral/activity.log', "Handling from live.\n", FILE_APPEND);
$query = DBFactory::getDBQuery();
if (function_exists('curl_init')) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "http://api.eve-central.com/api/marketstat?regionlimit=10000002&typeid=" . $item_id . "");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$content = curl_exec($ch);
curl_close($ch);
} else {
$file = fopen("http://api.eve-central.com/api/marketstat?regionlimit=10000002&typeid=" . $item_id . "", "r");
if (!$file) {
return -99;
}
$content = stream_get_contents($file);
fclose($file);
}
if (strpos($content, '</evec_api>') == false) {
return -99;
} else {
$parse = new XMLParser();
$parse->preparseXML();
$parse->parseXML($content);
$values = $parse->get_data();
if (0 == $values['WEIGHTED']) {
return -99;
}
$weighted_average = $values['WEIGHTED'];
}
file_put_contents(KB_CACHEDIR . '/evecentral/activity.log', "{$content}\n", FILE_APPEND);
$query->execute("REPLACE INTO kb3_eve_central (item_id, item_price) VALUES ({$item_id}, '{$weighted_average}')");
return $weighted_average;
}
示例5: getFAQ
public static function getFAQ()
{
if (!($data = @file_get_contents(self::getFilename()))) {
throw new ErrorException(self::ERROR_READING_FILE);
}
/**
* Let's replace some of the docbook tags and wrap some HTML-entities
* inside CDATA containers.
*/
$pattern = array('/<ulink\\s+url="(.+)">(.+)<\\/ulink>/isU', '/<itemizedlist>(.+)<\\/itemizedlist>/isU', '/<listitem><simpara>(.+)<\\/simpara><\\/listitem>/isU', '/<simpara>(.+)<\\/simpara>/isU', '/<emphasis>(.+)<\\/emphasis>/isU', '/<envar>(.+)<\\/envar>/isU', '/<command(?:\\s+[^>]+)?>(.+)<\\/command>/isU', '/<blockquote>(.+)<\\/blockquote>/isU', '/<programlisting(?:\\s+[^>]+)?>(.+)<\\/programlisting>/isU', '/<quote>(.+)<\\/quote>/isU', '/<xref linkend="(.+)"\\s+endterm=".+"\\/>/isU', '/(&(?:lt|gt|quot);)/is');
$replace = array('<h:a href="\\1">\\2</h:a>', '<h:ul>\\1</h:ul>', '<h:li>\\1</h:li>', '<h:p>\\1</h:p>', '<h:span class="italic">\\1</h:span>', '<h:span class="envar">\\1</h:span>', '<h:span class="bold">\\1</h:span>', '<h:blockquote>\\1</h:blockquote>', '<h:pre>\\1</h:pre>', '“<h:span class="quote">\\1</h:span>”', '<h:a xref="\\1"/>', '<![CDATA[\\1]]>');
$data = preg_replace($pattern, $replace, $data);
/* Remove this weird character as it displays as À in Firefox. */
$data = str_replace(chr(194), '', $data);
/* Now parse the data. */
$parser = new XMLParser();
$a = $parser->parseByData($data);
$sections = array();
/**
* Build a map of the defined hrefs so we can give the xrefs the correct
* text.
*/
$xref = array();
$count = 1;
foreach ($a['faq']['section'] as $data) {
$sections[] = new QASection($data, $count++, $xref);
}
return $sections;
}
示例6: sendHttp
public function sendHttp($url, $connectTimeout = "", $timeout)
{
// verify that the URL uses a supported protocol.
if (strpos($url, "http://") === 0 || strpos($url, "https://") === 0) {
//Construct the payload to POST to the url.
$data = $this->getRequestXml();
// create a new cURL resource
$ch = curl_init($url);
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
// Execute the request.
$result = curl_exec($ch);
$succeeded = curl_errno($ch) == 0 ? true : false;
// close cURL resource, and free up system resources
curl_close($ch);
// If Communication was not successful set error result, otherwise
if (!$succeeded) {
$result = $this->setErrorResponse(CENTINEL_ERROR_CODE_8030, CENTINEL_ERROR_CODE_8030_DESC);
}
// Assert that we received an expected Centinel Message in reponse.
if (strpos($result, "<CardinalMPI>") === false) {
$result = $this->setErrorResponse(CENTINEL_ERROR_CODE_8010, CENTINEL_ERROR_CODE_8010_DESC);
}
} else {
$result = $this->setErrorResponse(CENTINEL_ERROR_CODE_8000, CENTINEL_ERROR_CODE_8000_DESC);
}
$parser = new XMLParser();
$parser->deserializeXml($result);
$this->response = $parser->deserializedResponse;
}
示例7: array
/**
* Parse an XML file and return data in an array.
* @see xml.XMLParser::parseStruct()
*/
function &parseStruct($file, $tagsToMatch = array())
{
$parser = new XMLParser();
$data =& $parser->parseStruct($file, $tagsToMatch);
$parser->destroy();
return $data;
}
示例8: __update_cache
/**
* Update currency cache
*/
private function __update_cache($force = False)
{
if (!is_null($this->_cache) && !$force) {
return;
}
$filename = $this->path . 'data/iso_currencies.xml';
if (file_exists($filename)) {
// get XML file
$data = file_get_contents($filename);
$xml = new XMLParser($data, $filename);
$xml->Parse();
$currencies = array();
// create list with unique data
foreach ($xml->document->tagChildren as $iso_currency) {
// extract data
$entity = $iso_currency->tagChildren[0]->tagData;
$currency = $iso_currency->tagChildren[1]->tagData;
$alphabetic_code = $iso_currency->tagChildren[2]->tagData;
$numeric_code = $iso_currency->tagChildren[3]->tagData;
$minor_unit = $iso_currency->tagChildren[4]->tagData;
if ($numeric_code == '' || $alphabetic_code == 'XXX') {
continue;
}
$currencies[] = array('entity' => $entity, 'currency' => $currency, 'alphabetic_code' => $alphabetic_code, 'numeric_code' => $numeric_code, 'minor_unit' => $minor_unit);
// update cache
$this->_cache = $currencies;
}
}
}
示例9: 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();
}
示例10: testXml
/**
* 测试XML解析类
*/
function testXml()
{
$xml = file_get_contents('temp.xml');
$this->load->library('XMLParserLib');
$parser = new XMLParser($xml);
$parser->Parse();
print_r($parser->document->globalinfo);
//echo $parser->GenerateXML();
}
示例11: XMLParser
/**
* Parse a record's contents into an object
* @param $contents string
* @return object
*/
function &parseContents(&$contents)
{
$xmlParser = new XMLParser();
$result =& $xmlParser->parseText($contents);
$returner = array();
$returner =& $this->handleRootNode($result);
$result->destroy();
$xmlParser->destroy();
return $returner;
}
示例12: getAllArticles
public static function getAllArticles()
{
$fname = DIR_DATA . '/press_articles.xml';
$parser = new XMLParser();
$a = $parser->parseByFilename($fname);
$entries = array();
foreach ($a['articles']['article'] as $key => $value) {
$entries[] = new Article(array('name' => $value['name'], 'url' => $value['url'], 'language' => $value['language'], 'posted' => $value['posted']));
}
return $entries;
}
示例13: 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);
}
示例14: getAllMenus
public static function getAllMenus()
{
$fname = DIR_DATA . '/menus.xml';
$parser = new XMLParser();
$a = $parser->parseByFilename($fname);
$entries = array();
foreach ($a['menus']['group'] as $key => $value) {
$entries[] = new MenuItem(array('name' => $value['name'], 'class' => $value['class'], 'link' => $value['link']));
}
return $entries;
}
示例15: getAllCredits
public static function getAllCredits()
{
$fname = DIR_DATA . '/credits.xml';
$parser = new XMLParser();
$a = $parser->parseByFilename($fname);
$sections = array();
foreach ($a['credits']['section'] as $key => $value) {
$sections[] = new CSection($value);
}
return $sections;
}