本文整理汇总了PHP中SimpleXmlElement::asXML方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXmlElement::asXML方法的具体用法?PHP SimpleXmlElement::asXML怎么用?PHP SimpleXmlElement::asXML使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXmlElement
的用法示例。
在下文中一共展示了SimpleXmlElement::asXML方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _writeXml
protected function _writeXml()
{
// Write app/etc/modules/ file
$templateFilepath = __DIR__ . '/template/Migrated_FromCore.xml';
$moduleRegistrationDir = \Mage::getBaseDir('app') . '/etc/modules';
$moduleRegistrationFilepath = $moduleRegistrationDir . '/Migrated_FromCore.xml';
copy($templateFilepath, $moduleRegistrationFilepath);
echo "Writing {$moduleRegistrationFilepath}\r\n";
// Write etc/config.xml
$directory = \Mage::getBaseDir('app') . '/code/local/Migrated/FromCore/etc';
$filePath = $directory . "/config.xml";
echo "Writing {$filePath}\r\n";
mkdir($directory, 0755, true);
$this->_configXml->asXML($filePath);
}
示例2: arrayToXml
/**
* arrayToXml
*
* @param string $array Array to convert to xml
* @param string $rootNodeName Name of the root node
* @param string $xml SimpleXmlElement
* @return string $asXml String of xml built from array
*/
public static function arrayToXml($array, $rootNodeName = 'data', $xml = null)
{
if ($xml === null) {
$xml = new SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><{$rootNodeName}/>");
}
foreach ($array as $key => $value) {
$key = preg_replace('/[^a-z]/i', '', $key);
if (is_array($value) && !empty($value)) {
$node = $xml->addChild($key);
foreach ($value as $k => $v) {
if (is_numeric($v)) {
unset($value[$k]);
$node->addAttribute($k, $v);
}
}
self::arrayToXml($value, $rootNodeName, $node);
} else {
if (is_int($key)) {
$xml->addChild($value, 'true');
} else {
$value = htmlentities($value);
$xml->addChild($key, $value);
}
}
}
return $xml->asXML();
}
示例3: export
/**
* {@inheritdoc}
*/
public function export(array $data)
{
$countriesElement = new \SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><countries/>");
foreach ($data as $iso => $name) {
$countryElement = $countriesElement->addChild('country');
$countryElement->addChild('iso', $iso);
$countryElement->addChild('name', $countryElement->ownerDocument->createCDATASection($name));
}
return $countriesElement->asXML();
}
示例4: afterFeature
/**
* @return void
*/
public function afterFeature()
{
$this->testsuiteTimer->stop();
$testsuite = $this->currentTestsuite;
$testsuite->addAttribute('tests', array_sum($this->testsuiteStats));
$testsuite->addAttribute('failures', $this->testsuiteStats[TestResult::FAILED]);
$testsuite->addAttribute('skipped', $this->testsuiteStats[TestResult::SKIPPED]);
$testsuite->addAttribute('errors', $this->testsuiteStats[TestResult::PENDING]);
$testsuite->addAttribute('time', \round($this->testsuiteTimer->getTime(), 3));
$this->printer->write($this->xml->asXML());
}
示例5: send
public function send($method, $path = null, $data = array(), array $options = array())
{
$defaults = array('headers' => array('User-Agent' => 'Lava Surfboard'));
$xml = new \SimpleXmlElement('<request method="' . $path . '"></request>');
foreach ($data as $key => $val) {
if ($val != null) {
$xml->{$key} = $val;
}
}
$xmlString = $xml->asXML();
$data = str_replace("<?xml version=\"1.0\"?>\n", '<!--?xml version="1.0" encoding="utf-8"?-->', $xmlString);
$path = '/api/2.1/xml-in';
$response = parent::send($method, $path, $data, $options + $defaults);
return new \SimpleXmlElement($response);
}
示例6: arrayToXml
/**
* arrayToXml
*
* @param string $array Array to convert to xml
* @param string $rootNodeName Name of the root node
* @param string $xml SimpleXmlElement
* @return string $asXml String of xml built from array
*/
public function arrayToXml($array, $rootNodeName = 'data', $xml = null)
{
if ($xml === null) {
$xml = new SimpleXmlElement("<?xml version=\"1.0\" encoding=\"utf-8\"?><{$rootNodeName}/>");
}
foreach ($array as $key => $value) {
if (is_array($value)) {
$node = $xml->addChild($key);
$this->arrayToXml($value, $rootNodeName, $node);
} else {
$value = htmlentities($value);
$xml->addChild($key, $value);
}
}
return $xml->asXML();
}
示例7: saveFavouriteSites
/**
* Save given favourite site to xml file.
*/
public static function saveFavouriteSites($favId, $favType, $favName, $favLink, $configFilePath)
{
$favourites = FavouriteSitesUtil::getFavouriteSites($configFilePath);
if ($favType == "mixed") {
$favType = "movie";
}
$favourites[$favType] = array($favId, $favName, $favLink);
//Save to xml
$simpleXml = new SimpleXmlElement('<?xml version="1.0" encoding="UTF-8"?><favourite></favourite>');
foreach ($favourites as $type => $favourite) {
$element = $simpleXml->addChild("website", $favourite[2]);
$element->addAttribute("id", $favourite[0]);
$element->addAttribute("name", $favourite[1]);
$element->addAttribute("type", $type);
}
$fp = fopen($configFilePath, 'w');
fwrite($fp, $simpleXml->asXML());
fclose($fp);
}
示例8: SimpleXmlElement
<?php
$xml = new SimpleXmlElement(file_get_contents('messages/en/core.xml'));
$data = array();
foreach ($xml->entry as $entry) {
$data[(string) $entry['id']] = (string) $entry;
}
$keys = array_keys($data);
sort($keys);
$newXml = new SimpleXmlElement('<category id="core"></category>');
foreach ($keys as $key) {
$entry = $newXml->addChild("entry", $data[$key]);
$entry->addAttribute('id', $key);
}
$doc = new DOMDocument('1.0');
$doc->preserveWhiteSpace = false;
$doc->loadXML($newXml->asXML());
$doc->formatOutput = true;
file_put_contents('messages/en/core.xml', str_replace(' <entry', ' <entry', $doc->saveXML()));
示例9: uploadChanges
function uploadChanges($orderUuid, $courierUuid, $itineraryListNumber)
{
$itineraryListNumberUuid = "83b401b2-7643-11e4-90a2-8eca001235b3";
$employeeValueUuid = "83b40086-7643-11e4-90a2-8eca001235b2";
$oneOrderData = getOrderXmlFromMoysklad($orderUuid);
try {
$oneOrderXml = new SimpleXmlElement($oneOrderData);
} catch (Exception $e) {
echo "Возникла ошибка при загрузке данных о заказах покупателей с Moysklad. Пожалуйста, попробуйте еще раз.";
return;
}
$attributeExistsListNumber = false;
$attributeExistsEmployee = false;
$date = new DateTime("now", new DateTimeZone("Europe/Moscow"));
$date = $date->format('Y-m-d\\TH:i:s.uP');
foreach ($oneOrderXml->attribute as $attribute) {
if ($attribute["metadataUuid"] == $itineraryListNumberUuid) {
$attribute["longValue"] = $itineraryListNumber;
$attributeExistsListNumber = true;
}
if ($attribute["metadataUuid"] == $employeeValueUuid) {
$attribute["employeeValueUuid"] = $courierUuid;
$attributeExistsEmployee = true;
}
}
if (!$attributeExistsListNumber) {
$attribute = $oneOrderXml->addChild("attribute");
$attribute->addAttribute("operationUuid", $orderUuid);
$attribute->addAttribute("metadataUuid", $itineraryListNumberUuid);
$attribute->addAttribute("longValue", $itineraryListNumber);
$attribute->addAttribute("updated", $date);
$attribute->addAttribute("updatedBy", $GLOBALS["login"]);
$attribute->addAttribute("readMode", 'SELF');
$attribute->addAttribute("changeMode", 'SELF');
}
if (!$attributeExistsEmployee) {
$attribute = $oneOrderXml->addChild("attribute");
$attribute->addAttribute("operationUuid", $orderUuid);
$attribute->addAttribute("metadataUuid", $employeeValueUuid);
$attribute->addAttribute("employeeValueUuid", $courierUuid);
$attribute->addAttribute("updated", $date);
$attribute->addAttribute("updatedBy", $GLOBALS["login"]);
$attribute->addAttribute("readMode", 'SELF');
$attribute->addAttribute("changeMode", 'SELF');
}
$result = $oneOrderXml->asXML();
putOrderXmlToMoysklad($result);
}
示例10: SimpleXmlElement
<?php
$filename = "blog.xml";
if (file_exists($filename)) {
$rawBlog = file_get_contents($filename);
} else {
$rawBlog = <<<EOT
<?xml version="1.0" encoding="utf-8" ?>
<blog>
<title>YouCube</title>
<author>Ruby</author>
<entries><entries>
</blog>
EOT;
}
$xml = new SimpleXmlElement($rawBlog);
$entry = $xml->entries->addChild("entry");
$entry->addChild("date", $_REQUEST['date']);
$entry->addChild("body", stripslashes($_REQUEST["body"]));
if (empty($_REQUEST['image'])) {
$entry->addChild("image", $_REQUEST['image']);
}
$file = fopen($filename, 'w');
fwrite($file, $xml->asXML());
fclose($file);
示例11: createEmptyScrapers
private function createEmptyScrapers()
{
$simpleXml = new SimpleXmlElement('<?xml version="1.0" encoding="UTF-8"?><scrapers></scrapers>');
$fp = fopen($this->scrapersFilePath, 'w');
fwrite($fp, utf8_encode(html_entity_decode($simpleXml->asXML())));
fclose($fp);
}
示例12: toXml
/**
* Convert array to XML.
*
* @param array $array $array to convert.
* @param string $root Root node name.
* @param \SimpleXMLElement $xml Object for recursivity.
*
* @return string
*/
public static function toXml($array, $root = 'root', $xml = null)
{
if (is_null($xml)) {
$root = sprintf('<%s />', $root);
$xml = new \SimpleXmlElement($root);
}
foreach ($array as $key => $value) {
$key = is_numeric($key) ? 'row' : $key;
$key = preg_replace('/[^a-z]/i', '', $key);
if (is_array($value)) {
$node = $xml->addChild($key);
self::toXml($value, $root, $node);
} else {
$xml->addChild(strtolower($key), $value);
}
}
return $xml->asXML();
}
示例13: writeSvg
/**
* Based on image specification, write a very simple SVG file to disk.
* Ignores the background spec because transparency is cool. :)
*
* @param array $spec Spec describing background and shapes to draw
* @param string $format File format to write (which is obviously always svg here)
* @param string $filename Filename to write to
*
* @throws Exception
*/
public function writeSvg($spec, $format, $filename)
{
$svg = new SimpleXmlElement('<svg/>');
$svg->addAttribute('xmlns', 'http://www.w3.org/2000/svg');
$svg->addAttribute('version', '1.1');
$svg->addAttribute('width', $spec['width']);
$svg->addAttribute('height', $spec['height']);
$g = $svg->addChild('g');
foreach ($spec['draws'] as $drawSpec) {
$shape = $g->addChild('polygon');
$shape->addAttribute('fill', $drawSpec['fill']);
$shape->addAttribute('points', self::shapePointsToString($drawSpec['shape']));
}
if (!($fh = fopen($filename, 'w'))) {
throw new Exception("couldn't open {$filename} for writing");
}
fwrite($fh, $svg->asXML());
if (!fclose($fh)) {
throw new Exception("couldn't close {$filename}");
}
}
示例14: array
<element id="' . $productId . '" type="sprd:product" xlink:href="http://api.spreadshirt.de/api/v1/shops/1070242/products/' . $productId . '">
<properties>
<property key="appearance">' . $appearanceId . '</property>
<property key="size">' . $sizeId . '</property>
</properties>
</element>
</basketItem>');
$header = array();
$header[] = createSprdAuthHeader("PUT", $basketItemsURL);
$header[] = "Content-Type: application/xml";
$ch = curl_init($basketItemsURL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "PUT");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $basketItem->asXML());
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
$result = curl_exec($ch);
curl_close($ch);
echo json_encode("done");
// die();
}
if ($action == "read") {
$basketURL = "api.spreadshirt." . $tld . "/api/v1/baskets/" . $basketId;
$header = array();
$header[] = createSprdAuthHeader("GET", $basketURL);
$header[] = "Content-Type: application/xml";
$ch = curl_init($basketURL);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
示例15: SimpleXmlElement
$report_xml = new SimpleXmlElement($xml_base);
if (simplexml_load_string($row_spiel['bericht'])) {
$report_xml = new SimpleXmlElement($row_spiel['bericht']);
if (isset($report_xml->aufstellung->spieler)) {
//foreach($report_xml->aufstellung->spieler as $spieler_aufstellung){
$i = 0;
while (isset($report_xml->aufstellung->spieler[$i])) {
$spieler_aufstellung = $report_xml->aufstellung->spieler[$i];
if ($spieler_aufstellung['spieler_id'] == $spieler_id) {
if (!isset($spieler_aufstellung['confirmed'])) {
$spieler_aufstellung->addAttribute('confirmed', 'true');
} else {
$spieler_aufstellung['confirmed'] = "true";
}
//echo $spieler_aufstellung['confirmed'];
$bericht_xml = $report_xml->asXML();
$sql_update_bericht = "UPDATE `ergebnisse_{$_POST['liga_id']}` SET `bericht` = '{$bericht_xml}' WHERE `id` = {$_POST['spiel_id']}";
mysql_query('SET character_set_client = utf8');
mysql_query('SET character_set_results = utf8');
mysql_query('SET character_set_connection = utf8');
$result_berichte = mysql_query($sql_update_bericht) or die(mysql_error());
break;
}
$i++;
}
}
//print_r($report_xml);
}
}
}
}