本文整理汇总了PHP中simplexml_import_dom函数的典型用法代码示例。如果您正苦于以下问题:PHP simplexml_import_dom函数的具体用法?PHP simplexml_import_dom怎么用?PHP simplexml_import_dom使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了simplexml_import_dom函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Constructor
*
* @param string $xml is the string we want to parse
* @throws Exceptions\ParseException
*/
public function __construct($xml)
{
$this->xml = $xml;
libxml_use_internal_errors();
$dom = new DOMDocument();
$dom->recover = true;
$dom->strictErrorChecking = false;
$dom->loadXML($this->xml, LIBXML_NOCDATA);
$dom->encoding = self::ENCODING;
$opml = simplexml_import_dom($dom);
if ($opml === false) {
throw new Exceptions\ParseException('Provided XML document is not valid');
}
$this->result = ['version' => (string) $opml['version'], 'head' => [], 'body' => []];
if (!isset($opml->head)) {
throw new Exceptions\ParseException('Provided XML is not an valid OPML document');
}
// First, we get all "head" elements. Head is required but its sub-elements are optional.
foreach ($opml->head->children() as $key => $value) {
if (in_array($key, self::OPTIONAL_HEAD_ELEMENTS, true)) {
$this->result['head'][$key] = (string) $value;
}
}
if (!isset($opml->body)) {
return;
}
// Then, we get body outlines. Body must contain at least one outline element.
foreach ($opml->body->children() as $key => $value) {
if ($key === 'outline') {
$this->result['body'][] = $this->parseOutline($value);
}
}
}
示例2: run
function run($file)
{
require_once 'CRM/Core/DAO/CustomGroup.php';
require_once 'CRM/Core/DAO/CustomField.php';
require_once 'CRM/Core/DAO/OptionValue.php';
// read xml file
$dom = DomDocument::load($file);
$dom->xinclude();
$xml = simplexml_import_dom($dom);
$idMap = array('custom_group' => array(), 'option_group' => array());
// first create option groups and values if any
$this->optionGroups($xml, $idMap);
$this->optionValues($xml, $idMap);
$this->relationshipTypes($xml);
$this->contributionTypes($xml);
// now create custom groups
$this->customGroups($xml, $idMap);
$this->customFields($xml, $idMap);
// now create profile groups
$this->profileGroups($xml, $idMap);
$this->profileFields($xml, $idMap);
$this->profileJoins($xml, $idMap);
//create DB Template String sample data
$this->dbTemplateString($xml, $idMap);
}
示例3: loadRewrites
/**
* Return all rewrites
*
* @return array
*/
protected function loadRewrites()
{
$return = array('blocks', 'models', 'helpers');
// Load config of each module because modules can overwrite config each other. Globl config is already merged
$modules = Mage::getConfig()->getNode('modules')->children();
foreach ($modules as $moduleName => $moduleData) {
// Check only active modules
if (!$moduleData->is('active')) {
continue;
}
// Load config of module
$configXmlFile = Mage::getConfig()->getModuleDir('etc', $moduleName) . DIRECTORY_SEPARATOR . 'config.xml';
if (!file_exists($configXmlFile)) {
continue;
}
$xml = simplexml_load_file($configXmlFile);
if ($xml) {
$rewriteElements = $xml->xpath('//rewrite');
foreach ($rewriteElements as $element) {
foreach ($element->children() as $child) {
$type = simplexml_import_dom(dom_import_simplexml($element)->parentNode->parentNode)->getName();
if (!in_array($type, $this->_rewriteTypes)) {
continue;
}
$groupClassName = simplexml_import_dom(dom_import_simplexml($element)->parentNode)->getName();
if (!isset($return[$type][$groupClassName . '/' . $child->getName()])) {
$return[$type][$groupClassName . '/' . $child->getName()] = array();
}
$return[$type][$groupClassName . '/' . $child->getName()][] = (string) $child;
}
}
}
}
return $return;
}
示例4: decode
/**
* {@inheritdoc}
*/
public function decode($data, $format)
{
$internalErrors = libxml_use_internal_errors(true);
$disableEntities = libxml_disable_entity_loader(true);
libxml_clear_errors();
$dom = new \DOMDocument();
$dom->loadXML($data, LIBXML_NONET);
libxml_use_internal_errors($internalErrors);
libxml_disable_entity_loader($disableEntities);
foreach ($dom->childNodes as $child) {
if ($child->nodeType === XML_DOCUMENT_TYPE_NODE) {
throw new UnexpectedValueException('Document types are not allowed.');
}
}
$xml = simplexml_import_dom($dom);
if ($error = libxml_get_last_error()) {
throw new UnexpectedValueException($error->message);
}
if (!$xml->count()) {
if (!$xml->attributes()) {
return (string) $xml;
}
$data = array();
foreach ($xml->attributes() as $attrkey => $attr) {
$data['@' . $attrkey] = (string) $attr;
}
$data['#'] = (string) $xml;
return $data;
}
return $this->parseXml($xml);
}
示例5: dom
public static function dom($stream)
{
rewind($stream);
$actual = stream_get_contents($stream);
$html = DOMDocument::loadHTML($actual);
return simplexml_import_dom($html);
}
示例6: extract_vals
function extract_vals($td_children)
{
global $val, $key, $results, $line_broken;
for ($i = 0; $i < $td_children->length; $i++) {
$item = $td_children->item($i);
switch ($item->nodeType) {
case XML_TEXT_NODE:
if (!$line_broken) {
$val .= $item->textContent;
}
break;
case XML_ELEMENT_NODE:
switch (strtolower($item->tagName)) {
case 'b':
push_val($item);
break;
case 'a':
if (!$line_broken) {
$val .= $item->textContent;
}
break;
case 'br':
$line_broken = true;
break;
case 'table':
if (!count($results)) {
@extract_vals(dom_import_simplexml(simplexml_import_dom($item)->tr[0]->td[0])->childNodes);
}
break 3;
case 'hr':
break 3;
}
}
}
}
示例7: optimize
public function optimize($buffer)
{
$output = '';
// matched buffer comes in from preg_replace_callback() as array
$buffer = $buffer[0];
$dom = new DOMDocument();
$dom->loadHTML($buffer);
$html = simplexml_import_dom($dom);
// gather file names -
// get URL's for each CSS file in each CSS tag of the HTML block
$files = array();
foreach ($html->head->link as $link) {
// filter out things like favicon
if ((string) $link['rel'] == 'stylesheet') {
$file = trim((string) $link['href']);
$files[] = trim($file, '/');
}
}
// build the combined, minified output file
// the latest mod time of the set is in output file name
try {
$outfile = $this->_getName($files);
$this->_phing->log("Building {$this->_toDir}/{$outfile}");
$this->_build($outfile, $files);
} catch (Exception $e) {
throw new BuildException($e->getMessage());
}
// output the static CSS tag
$twoBitValue = 0x3 & crc32("{$outfile}");
$host = str_replace('?', $twoBitValue, $this->_host);
$path = "http://{$host}/{$outfile}";
$output = "<link href=\"{$path}\" rel=\"stylesheet\" type=\"text/css\" />\n";
return $output;
}
示例8: handle
/**
* parse FolderDelete request
*/
public function handle()
{
$xml = simplexml_import_dom($this->_requestBody);
// parse xml request
$syncKey = (int) $xml->SyncKey;
$serverId = (string) $xml->ServerId;
if ($this->_logger instanceof Syncroton_Log) {
$this->_logger->debug(__METHOD__ . '::' . __LINE__ . " synckey is {$syncKey}");
}
if (!($this->_syncState = $this->_syncStateBackend->validate($this->_device, 'FolderSync', $syncKey)) instanceof Syncroton_Model_SyncState) {
return;
}
try {
$folder = $this->_folderBackend->getFolder($this->_device, $serverId);
$dataController = Syncroton_Data_Factory::factory($folder->class, $this->_device, $this->_syncTimeStamp);
// delete folder in data backend
$dataController->deleteFolder($folder);
} catch (Syncroton_Exception_NotFound $senf) {
if ($this->_logger instanceof Syncroton_Log) {
$this->_logger->debug(__METHOD__ . '::' . __LINE__ . " " . $senf->getMessage());
}
return;
}
// delete folder in syncState backend
$this->_folderBackend->delete($folder);
$this->_folder = $folder;
}
示例9: generateContent
public function generateContent()
{
// Can't download the documectation directly (required facebook login)
$form = new Form(array('class' => 'form-horizontal', 'legend' => 'Paste HTML from https://developers.facebook.com/docs/reference/api/$model/', 'fields' => array('HTML' => new Input(array('type' => 'textarea', 'name' => 'source')), new Input(array('type' => 'submit', 'value' => 'Generate class', 'class' => 'btn btn-primary')))));
$data = $form->import($error);
if ($data) {
$dom = new \DOMDocument();
@$dom->loadHTML($data['source']);
$xml = simplexml_import_dom($dom);
$link = $xml->xpath('//div[@class="breadcrumbs"]/a[last()]');
$path = explode('/', trim($link[0]['href'], '/'));
$elements = $xml->xpath('//div[@id="bodyText"]');
$info = array('class' => ucfirst(end($path)), 'link' => 'https://developers.facebook.com/' . implode('/', $path) . '/', 'description' => strip_tags($elements[0]->p[0]->asXML()), 'fields' => $this->extractFields($elements[0]->table[0]->tr), 'connections' => array(), 'constructor' => strpos($elements[0]->table[0]->asXML(), 'only returned if'));
if ($elements[0]->table[1] !== null) {
$info['connections'] = $this->extractFields($elements[0]->table[1]->tr);
}
if (count($info['fields']) == 0 && count($info['connections']) != 0) {
// Thread documentation
$info['fields'] = $info['connections'];
$info['connections'] = $this->extractFields($elements[0]->table[2]->tr);
}
return new Dump($this->generatePhp($info));
} else {
return $form;
}
}
示例10: _parse_xml
/**
* parse XML file into data array
*
* @param string $file path to XML file
* @return array parsed data
* @since 1.0.1
*/
public function _parse_xml($file)
{
$file_content = file_get_contents($file);
$file_content = iconv('utf-8', 'utf-8//IGNORE', $file_content);
$file_content = preg_replace('/[^\\x{0009}\\x{000a}\\x{000d}\\x{0020}-\\x{D7FF}\\x{E000}-\\x{FFFD}]+/u', '', $file_content);
if (!$file_content) {
return false;
}
$dom = new DOMDocument('1.0');
$dom->loadXML($file_content);
$xml = simplexml_import_dom($dom);
$old_upload_url = $xml->xpath('/rss/channel/wp:base_site_url');
$old_upload_url = $old_upload_url[0];
$upload_dir = wp_upload_dir();
$upload_url = $upload_dir['url'] . '/';
$upload_dir = $upload_dir['url'];
$cut_upload_dir = substr($upload_dir, strpos($upload_dir, 'wp-content/uploads'), strlen($upload_dir) - 1);
$cut_date_upload_dir = '<![CDATA[' . substr($upload_dir, strpos($upload_dir, 'wp-content/uploads') + 19, strlen($upload_dir) - 1);
$cut_date_upload_dir_2 = "\"" . substr($upload_dir, strpos($upload_dir, 'wp-content/uploads') + 19, strlen($upload_dir) - 1);
$pattern = '/[\\"\']http:.{2}(?!livedemo).[^\'\\"]*wp-content.[^\'\\"]*\\/(.[^\\/\'\\"]*\\.(?:jp[e]?g|png|mp4|webm|ogv))[\\"\']/i';
$patternCDATA = '/<!\\[CDATA\\[\\d{4}\\/\\d{2}/i';
$pattern_meta_value = '/("|\')\\d{4}\\/\\d{2}/i';
$file_content = str_replace($old_upload_url, site_url(), $file_content);
$file_content = preg_replace($patternCDATA, $cut_date_upload_dir, $file_content);
$file_content = preg_replace($pattern_meta_value, $cut_date_upload_dir_2, $file_content);
$file_content = preg_replace($pattern, '"' . $upload_url . '$1"', $file_content);
$parser = new Cherry_WXR_Parser();
$parser_array = $parser->parse($file_content, $file);
return $parser_array;
}
示例11: indexAction
public function indexAction()
{
SxCms_Acl::requireAcl('ad', 'ad.edit');
$filename = APPLICATION_PATH . '/var/ads.xml';
$dom = new DOMDocument();
$dom->preserveWhiteSpace = false;
$dom->loadXml(file_get_contents($filename));
$dom->formatOutput = true;
$xpath = new DOMXpath($dom);
$xml = simplexml_import_dom($dom);
if ($this->getRequest()->isPost()) {
$ads = $this->_getParam('ad');
foreach ($ads as $key => $value) {
$nodeList = $xpath->query("//zone[id='{$key}']/content");
if ($nodeList->length) {
$cdata = $dom->createCDATASection(stripslashes($value));
$content = $dom->createElement('content');
$content->appendChild($cdata);
$nodeList->item(0)->parentNode->replaceChild($content, $nodeList->item(0));
}
}
$dom->save($filename);
$flashMessenger = $this->_helper->getHelper('FlashMessenger');
$flashMessenger->addMessage('Advertentie werd succesvol aangepast');
}
$this->view->ads = $xml;
}
示例12: __doRequest
public function __doRequest($request, $location, $action, $version, $one_way = null)
{
$api = $this->getBaseApi();
$user = $api->getConfigData('merchant_id');
$password = $api->getConfigData('security_key');
$soapHeader = "<SOAP-ENV:Header xmlns:SOAP-ENV=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:wsse=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd\"><wsse:Security SOAP-ENV:mustUnderstand=\"1\"><wsse:UsernameToken><wsse:Username>{$user}</wsse:Username><wsse:Password Type=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText\">{$password}</wsse:Password></wsse:UsernameToken></wsse:Security></SOAP-ENV:Header>";
$requestDOM = new DOMDocument('1.0');
$soapHeaderDOM = new DOMDocument('1.0');
$requestDOM->loadXML($request);
$soapHeaderDOM->loadXML($soapHeader);
$node = $requestDOM->importNode($soapHeaderDOM->firstChild, true);
$requestDOM->firstChild->insertBefore($node, $requestDOM->firstChild->firstChild);
$request = $requestDOM->saveXML();
if ($api->getConfigData('debug')) {
/*Clean up PAN and CV2 for debug*/
$clean = simplexml_import_dom($requestDOM);
$del = $clean->xpath('//ns1:accountNumber | //ns1:cvNumber');
foreach ($del as $el) {
$el[0] = '';
}
$debugrequest = $clean->asXML();
$debug = Mage::getModel('cybersource/api_debug')->setAction($action)->setRequestBody($debugrequest)->save();
}
$response = parent::__doRequest($request, $location, $action, $version);
if (!empty($debug)) {
$debug->setResponseBody($response)->save();
}
return $response;
}
示例13: addTax
function addTax(SimpleXMLElement $taxes, SimpleXMLElement $tax, array $attributesToUpdate = array(), array $attributesToRemove = array())
{
$newTax = new SimpleXMLElement('<tax/>');
$taxRulesGroups = $taxes->xpath('//taxRulesGroup[1]');
$insertBefore = $taxRulesGroups[0];
if (!$insertBefore) {
die("Could not find any `taxRulesGroup`, don't know where to append the tax.\n");
}
/**
* Add the `tax` node before the first `taxRulesGroup`.
* Yes, the dom API is beautiful.
*/
$dom = dom_import_simplexml($taxes);
$new = $dom->insertBefore($dom->ownerDocument->importNode(dom_import_simplexml($newTax)), dom_import_simplexml($insertBefore));
$newTax = simplexml_import_dom($new);
$newAttributes = array();
foreach ($tax->attributes() as $attribute) {
$name = $attribute->getName();
// This attribute seems to cause trouble, skip it.
if ($name === 'account_number' || in_array($name, $attributesToRemove)) {
continue;
}
$value = (string) $attribute;
$newAttributes[$name] = $value;
}
$newAttributes = array_merge($newAttributes, $attributesToUpdate);
foreach ($newAttributes as $name => $value) {
$newTax->addAttribute($name, $value);
}
return $newTax;
}
示例14: hydrate
public function hydrate(\DOMNode $node)
{
$pupil = simplexml_import_dom($node);
/** @var Pupil $entity */
$entity = $this->entity->newInstance();
$entity->setId((int) $pupil->attributes()->Id);
$entity->setEmail((string) $pupil->EmailAddress);
$entity->setName((string) $pupil->Fullname);
$entity->setSchoolCode((string) $pupil->SchoolCode);
$entity->setSchoolId((string) $pupil->SchoolId);
$entity->setUserCode((string) $pupil->UserCode);
$entity->setUserName((string) $pupil->UserName);
$entity->setTitle((string) $pupil->Title);
$entity->setForename((string) $pupil->Forename);
$entity->setSurname((string) $pupil->Surname);
$entity->setMiddlename((string) $pupil->Middlename);
$entity->setInitials((string) $pupil->Initials);
$entity->setPreferredName((string) $pupil->Preferredname);
$entity->setFullname((string) $pupil->Fullname);
$entity->setGender((string) $pupil->Gender);
$entity->setDOB((string) $pupil->DOB);
$entity->setBoardingHouse((string) $pupil->BoardingHouse);
$entity->setNCYear((string) $pupil->NCYear);
$entity->setPupilType((string) $pupil->PupilType);
$entity->setEnrolmentDate((string) $pupil->EnrolmentDate);
$entity->setEnrolmentTerm((string) $pupil->EnrolmentTerm);
$entity->setEnrolmentSchoolYear((string) $pupil->EnrolmentSchoolYear);
return $entity;
}
示例15: handle
/**
*/
public function handle()
{
$xml = simplexml_import_dom($this->_inputDom);
foreach ($xml->Collections->Collection as $xmlCollection) {
// fetch values from a different namespace
$airSyncValues = $xmlCollection->children('uri:AirSync');
$collectionData = array('syncKey' => (int) $airSyncValues->SyncKey, 'class' => (string) $xmlCollection->Class, 'collectionId' => (string) $xmlCollection->CollectionId, 'filterType' => isset($airSyncValues->FilterType) ? (int) $airSyncValues->FilterType : 0);
if ($this->_logger instanceof Zend_Log) {
$this->_logger->info(__METHOD__ . '::' . __LINE__ . " synckey is {$collectionData['syncKey']} class: {$collectionData['class']} collectionid: {$collectionData['collectionId']} filtertype: {$collectionData['filterType']}");
}
try {
// does the folder exist?
$collectionData['folder'] = $this->_folderBackend->getFolder($this->_device, $collectionData['collectionId']);
$collectionData['folder']->lastfiltertype = $collectionData['filterType'];
if ($collectionData['syncKey'] === 0) {
$collectionData['syncState'] = new Syncope_Model_SyncState(array('device_id' => $this->_device, 'counter' => 0, 'type' => $collectionData['folder'], 'lastsync' => $this->_syncTimeStamp));
// reset sync state for this folder
$this->_syncStateBackend->resetState($this->_device, $collectionData['folder']);
$this->_contentStateBackend->resetState($this->_device, $collectionData['folder']);
} else {
$collectionData['syncState'] = $this->_syncStateBackend->validate($this->_device, $collectionData['folder'], $collectionData['syncKey']);
}
} catch (Syncope_Exception_NotFound $senf) {
if ($this->_logger instanceof Zend_Log) {
$this->_logger->debug(__METHOD__ . '::' . __LINE__ . " " . $senf->getMessage());
}
}
$this->_collections[$collectionData['collectionId']] = $collectionData;
}
}