本文整理汇总了PHP中SimpleXMLElement::asXML方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLElement::asXML方法的具体用法?PHP SimpleXMLElement::asXML怎么用?PHP SimpleXMLElement::asXML使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLElement
的用法示例。
在下文中一共展示了SimpleXMLElement::asXML方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: cron
protected function cron(array $args = array())
{
//TODO Данные об индексируемых страницах брать из ResManager
global $general_s;
//TODO переделать global на параметры
$this->sxe = new \SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>' . '<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"></urlset>');
// Главная
$this->addUrlToSitemap('/', time(), self::NODE_CHANGEFREQ_DAILY, 1.0);
// Категории
$categories = $this->repositoryFactory->getCategoryRepository()->query()->getEntity(PHP_INT_MAX);
foreach ($categories as $category) {
$this->addUrlToSitemap("/category/{$category->id}", null, self::NODE_CHANGEFREQ_DAILY);
}
unset($categories);
// Вопросы
$mainQuestions = $this->repositoryFactory->getMainQuestionRepository()->query()->addFilterField('active', true)->getEntity(PHP_INT_MAX);
foreach ($mainQuestions as $mainQuestion) {
$this->addUrlToSitemap("/question/{$mainQuestion->id}", $mainQuestion->createDate);
}
unset($mainQuestions);
// Сохранение XML
$result = $this->sxe->asXML(pathinfo($_SERVER['SCRIPT_FILENAME'], PATHINFO_DIRNAME) . "/{$general_s['sitemap_file']}");
if ($result === false) {
$this->setResponseCode(HttpResponseCode::INTERNAL_SERVER_ERROR);
$this->addResponseMessage("Ошибка создания карты сайта! Проверьте права на запись в файл " . basename($general_s['sitemap_file']), self::MESS_ERROR);
} else {
$this->addResponseMessage('Карта сайта успешно создана!');
}
unset($this->sxe);
}
示例2: buildXml
public function buildXml($xml)
{
$this->root->asXML($xml);
$xmlContent = $this->getContentXMLFile($xml);
$this->deleteXMLFile($xml);
return $xmlContent;
}
示例3: asPrettyXML
/**
* Format xml with indents and line breaks
*
* @return string
* @author Gary Malcolm
*/
public function asPrettyXML()
{
$string = $this->_xml->asXML();
// put each element on it's own line
$string = preg_replace("/>\\s*</", ">\n<", $string);
// each element to own array
$xmlArray = explode("\n", $string);
// holds indentation
$currIndent = 0;
$indent = " ";
// set xml element first by shifting of initial element
$string = array_shift($xmlArray) . "\n";
foreach ($xmlArray as $element) {
// find open only tags... add name to stack, and print to string
// increment currIndent
if (preg_match('/^<([\\w])+[^>\\/]*>$/U', $element)) {
$string .= str_repeat($indent, $currIndent) . $element . "\n";
$currIndent += 1;
} elseif (preg_match('/^<\\/.+>$/', $element)) {
$currIndent -= 1;
$string .= str_repeat($indent, $currIndent) . $element . "\n";
} else {
$string .= str_repeat($indent, $currIndent) . $element . "\n";
}
}
return $string;
}
示例4: log
/**
* This method saves all RatePAY Requests and Responses in the database
*
* @param array $loggingInfo
* @param SimpleXMLElement|null $request
* @param SimpleXMLElement|null $response
*/
public function log($loggingInfo, $request, $response)
{
$responseXML = '';
$result = "Service offline.";
$resultCode = "Service offline.";
$reasonText = '';
if (isset($request->content->customer->{'bank-account'})) {
$request->content->customer->{'bank-account'}->owner = '(hidden)';
if (isset($request->content->customer->{'bank-account'}->{'iban'})) {
$request->content->customer->{'bank-account'}->{'iban'} = '(hidden)';
$request->content->customer->{'bank-account'}->{'bic-swift'} = '(hidden)';
} else {
$request->content->customer->{'bank-account'}->{'bank-account-number'} = '(hidden)';
$request->content->customer->{'bank-account'}->{'bank-code'} = '(hidden)';
}
}
if ($response != null && isset($response) && $response->asXML() != '') {
$result = (string) $response->head->processing->result;
$resultCode = (string) $response->head->processing->result->attributes()->code;
$responseXML = $response->asXML();
$reasonText = (string) $response->head->processing->reason;
if ($loggingInfo['requestType'] == 'PAYMENT_INIT') {
$loggingInfo['transactionId'] = (string) $response->head->{'transaction-id'};
}
}
$this->setId(null)->setOrderNumber(!empty($loggingInfo['orderId']) ? $loggingInfo['orderId'] : 'n/a')->setTransactionId(!empty($loggingInfo['transactionId']) ? $loggingInfo['transactionId'] : 'n/a')->setPaymentMethod(!empty($loggingInfo['paymentMethod']) ? $loggingInfo['paymentMethod'] : 'n/a')->setPaymentType(!empty($loggingInfo['requestType']) ? $loggingInfo['requestType'] : 'n/a')->setPaymentSubtype(!empty($loggingInfo['requestSubType']) ? $loggingInfo['requestSubType'] : 'n/a')->setResult($result)->setRequest($request->asXML())->setRequest($request->asXML())->setResponse($responseXML)->setResultCode($resultCode)->setName($loggingInfo['firstName'] . " " . $loggingInfo['lastName'])->setReason($reasonText)->save();
}
示例5: createFile
/**
* Export
*/
protected function createFile()
{
$this->XML = new \SimpleXMLElement($this->emptyXml());
$this->Track = $this->XML->trk->trkseg;
$this->setTrack();
$this->FileContent = $this->XML->asXML();
$this->formatFileContentAsXML();
}
示例6: dump
/**
* Dump manifest structure into a XML string.
*
* @return string
*/
public function dump()
{
// Create a new XML document
$document = new \DOMDocument('1.0', 'utf-8');
$document->preserveWhiteSpace = false;
$document->formatOutput = true;
$document->loadXML($this->xml->asXML());
return $document->saveXML();
}
示例7: createFile
/**
* Export
*/
protected function createFile()
{
$this->XML = new \SimpleXMLElement($this->emptyXml());
$this->Activity = $this->XML->AthleteLog->Activity;
$this->setGeneralInfo();
$this->setTrack();
$this->FileContent = $this->XML->asXML();
$this->formatFileContentAsXML();
}
示例8: createFile
/**
* Export
*/
protected function createFile()
{
$this->XML = new \SimpleXMLElement($this->emptyXml());
$this->Activity = $this->XML->Activities->Activity;
$this->setInternalIndicators();
$this->setGeneralInfo();
$this->setLaps();
$this->FileContent = $this->XML->asXML();
$this->formatFileContentAsXML();
}
示例9: saveConfig
public static function saveConfig()
{
$filePath = getcwd() . self::CONFIG_FOLDER . self::CONFIG_NAME;
if (!empty(self::$configTree)) {
$dom = new \DOMDocument("1.0");
$dom->formatOutput = true;
$dom->loadXML(self::$configTree->asXML());
file_put_contents($filePath, $dom->saveXML());
}
}
示例10: createItem
/**
* Insert a row into the blacklist.xml
*
* @param type $type
* @param type $table
* @param type $colum
*/
function createItem($type, $table, $colum)
{
$library = new SimpleXMLElement('xml/blacklist.xml', null, true);
$book = $library->addChild('ITEM');
$book->addAttribute('ID', $this->getLastIDItem() + 1);
$book->addChild('TYPE', $type);
$book->addChild('TABLE', $table);
$book->addChild('COLUMN', $colum);
echo $library->asXML();
$library->asXML('xml/blacklist.xml');
}
示例11: setFileContent
/**
* Set file content
*/
protected function setFileContent()
{
if (!$this->Context->hasRoute() || !$this->Context->route()->hasPositionData()) {
$this->addError(__('The training does not contain gps-data and cannot be saved as gpx-file.'));
return;
}
$this->XML = new SimpleXMLElement($this->getEmptyXml());
$this->Track = $this->XML->trk->trkseg;
$this->setTrack();
$this->FileContent = $this->XML->asXML();
$this->formatFileContentAsXML();
}
示例12: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
//Проверим запущена ли команда уже, если да то выходим
$lockHandler = new LockHandler('xml.generate.lock');
if (!$lockHandler->lock()) {
$output->writeln('Command is locked');
return 0;
}
$email = $input->getArgument('email');
if ($email && !filter_var($email, FILTER_VALIDATE_EMAIL)) {
throw new InvalidArgumentException('The argument must be valid email');
}
$container = $this->getContainer();
$em = $container->get('doctrine.orm.entity_manager');
$persons = $em->getRepository('AppBundle:Person')->findAll();
$serializer = SerializerBuilder::create()->build();
//ищем файл XML для экспорта, если нет - создаем
$fs = new Filesystem();
$path = $container->get('kernel')->getRootDir() . '/data/result.xml';
if ($fs->exists($path)) {
$content = file_get_contents($path);
$xml = new \SimpleXMLElement($content);
} else {
$xml = new \SimpleXMLElement('<persons/>');
$xml->asXML($path);
}
//идем по всем Person и ищем соответствующий айди в XML
foreach ($persons as $person) {
$serialized = $serializer->serialize($person, 'xml');
$t = $xml->xpath(sprintf('//person[@id="%d"]', $person->getId()));
if ($t) {
//если находим - удаляем нод
$dom = dom_import_simplexml($t[0]);
$dom->parentNode->removeChild($dom);
}
//вставляем новый нод
$target = $xml->xpath('/persons');
$dom = dom_import_simplexml($target[0]);
$insertDom = $dom->ownerDocument->importNode(dom_import_simplexml(new \SimpleXMLElement($serialized)), true);
$dom->appendChild($insertDom);
}
$xml->asXML($path);
$publicPath = $container->get('kernel')->getRootDir() . '/../web/' . XmlCommand::XML_PATH;
$fs->copy($path, $publicPath);
$timeFinished = new \DateTime();
if ($email) {
$context = $container->get('router')->getContext();
$message = \Swift_Message::newInstance()->setSubject('Task finished')->setFrom('noreply@' . $context->getHost())->setTo($email)->setBody($container->get('templating')->render('emails/xmlFinished.html.twig', ['taskName' => XmlCommand::TASK_NAME, 'time' => $timeFinished, 'link' => $context->getHost() . '/' . XmlCommand::XML_PATH]), 'text/html');
$container->get('mailer')->send($message);
}
return 0;
}
示例13: setFileContent
/**
* Set file content
*/
protected function setFileContent()
{
if (!$this->Context->hasRoute() || !$this->Context->route()->hasPositionData()) {
$this->addError(__('The training does not contain gps-data and cannot be saved as tcx-file.'));
return;
}
$this->XML = new SimpleXMLElement($this->getEmptyXml());
$this->Activity = $this->XML->Activities->Activity;
$this->setGeneralInfo();
$this->setLaps();
$this->FileContent = $this->XML->asXML();
$this->formatFileContentAsXML();
}
示例14: send
/**
* @param string|null $expectedResponse the response type which expected
* @param bool $useSession should the request use an automatic session id?
* @param bool $secondFail is this the second try of this request?
* @return \SimpleXMLElement
* @throws \Exception
*/
public function send($expectedResponse = null, $useSession = true, $try = 1)
{
$this->request['RequestId'] = '33300000-2200-1000-0000-' . substr(md5(uniqid()), 0, 12);
$this->request['Version'] = $this->smartHome->getVersion();
if ($useSession) {
$this->request['SessionId'] = $this->smartHome->getSessionId();
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://' . $this->smartHome->getHost() . '/' . $this->action);
if (($clientId = $this->smartHome->getClientId()) !== null || $this->action === 'upd') {
if ($clientId === null && $this->action === 'upd') {
throw new \Exception('Unable to get updates if no client id is specified!', 107);
}
curl_setopt($ch, CURLOPT_HTTPHEADER, array('ClientId: ' . $clientId));
}
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_POSTFIELDS, $this->action === 'upd' ? 'upd' : $this->request->asXML());
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
list($header, $body) = explode("\r\n\r\n", curl_exec($ch), 2);
$this->setResponse($body);
$this->setResponseHeader($header);
curl_close($ch);
/**
* Fix the problems
*/
$responseType = (string) $this->getResponse()->attributes('xsi', true)->type;
if ($expectedResponse !== null && strtolower($responseType) !== strtolower($expectedResponse)) {
if ($try > 1) {
throw new \Exception('Request failed second time. Error: ' . $responseType, 99);
}
if ($responseType === 'GenericSHCErrorResponse' || $responseType === 'AuthenticationErrorResponse') {
$this->smartHome->login(++$try);
return $this->send($expectedResponse, $useSession, $try);
} else {
$try--;
}
if ($responseType === 'VersionMismatchErrorResponse') {
$this->smartHome->setVersion((string) $this->getResponse()->attributes()->ExpectedVersion);
return $this->send($expectedResponse, $useSession, ++$try);
} else {
$try--;
}
}
return $this->getResponse();
}
示例15: execute
public function execute()
{
//Build command arguments..
foreach ($this->arguments as $arg) {
$this->command->addChild("arg", $arg);
}
$reqStr = $this->request->asXML();
$curl = curl_init("http://localhost:8181/rpc/surrogate_api/xmlcmd");
curl_setopt($curl, CURLOPT_POST, TRUE);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($curl, CURLOPT_POSTFIELDS, $reqStr);
//echo "Requesting: \n$reqStr\n\n";
$this->response = curl_exec($curl);
curl_close($curl);
}