本文整理汇总了PHP中SimpleXMLElement::asXml方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLElement::asXml方法的具体用法?PHP SimpleXMLElement::asXml怎么用?PHP SimpleXMLElement::asXml使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLElement
的用法示例。
在下文中一共展示了SimpleXMLElement::asXml方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setJob
function setJob($name, $template, $replacements = array())
{
$job_xml = file_get_contents('templates/' . $template . '.xml', 'r');
foreach ($replacements as $search => $replace) {
$job_xml = str_replace('{{{' . $search . '}}}', $replace, $job_xml);
}
$job = new SimpleXMLElement($job_xml);
$job->displayName = $name;
// Existing job.
if (isset($this->getJobs()[$name])) {
return $this->conn->post('job/' . $name . '/config.xml', ['body' => $job->asXml(), 'headers' => ['Content-Type' => 'application/xml']]);
}
// New job.
return $this->conn->post('createItem', ['body' => $job->asXml(), 'headers' => ['Content-Type' => 'application/xml'], 'query' => ['name' => $name]]);
}
示例2: act_packages
public function act_packages()
{
$packages = Posts::get(array('content_type' => 'plugin', 'nolimit' => true));
$xml = new SimpleXMLElement('<packages/>');
foreach ($packages as $package) {
if (!$package->info->guid) {
continue;
}
$package_node = $xml->addChild('package');
$package_node->addChild('description', utf8_encode(Format::summarize(strip_tags($package->content))));
$package_node->addAttribute('guid', $package->info->guid);
$package_node->addAttribute('name', $package->title);
if ($package->info->author) {
$package_node->addAttribute('author', $package->info->author);
}
if ($package->info->author_url) {
$package_node->addAttribute('author_url', $package->info->author_url);
}
$package_node->addAttribute('type', 'plugin');
$package_node->addAttribute('tags', implode(',', (array) $package->tags));
$versions_node = $package_node->addChild('versions');
foreach ($package->versions as $version) {
if ($version->habari_version) {
$version_node = $versions_node->addChild('version', $version->description);
$version_node->addAttribute('version', $version->version);
$version_node->addAttribute('archive_md5', $version->md5);
$version_node->addAttribute('archive_url', $version->url);
$version_node->addAttribute('habari_version', $version->habari_version);
}
}
}
ob_clean();
header('Content-Type: application/xml');
echo $xml->asXml();
}
示例3: toXml
function toXml()
{
$baseStr = '<?xml version="1.0" standalone="yes"?><tree id="0"></tree>';
$xml = new SimpleXMLElement($baseStr);
$currentLevel = array($xml);
$currentRgt = 0;
foreach ($this->_tree as $key => $row) {
if ($key == 0) {
$currentLevel[0]->addAttribute('lft', $row['lft']);
$currentLevel[0]->addAttribute('rgt', $row['rgt']);
continue;
} elseif ($row['lft'] > $currentLevel[count($currentLevel) - 1]->attributes()->rgt) {
while ($row['lft'] > $currentLevel[count($currentLevel) - 1]->attributes()->rgt) {
array_pop($currentLevel);
}
}
$node = $currentLevel[count($currentLevel) - 1]->addChild('item');
$node->addAttribute('id', $row['enumerationId']);
$node->addAttribute('text', $row['name']);
$node->addAttribute('lft', $row['lft']);
$node->addAttribute('rgt', $row['rgt']);
if ($row['rgt'] > $row['lft'] + 1) {
$node->addAttribute('child', 1);
array_push($currentLevel, $node);
$currentRgt = $row['rgt'];
} elseif ($row['rgt'] + 1 == $currentRgt) {
array_pop($currentLevel);
$node->addAttribute('curRgt', $currentLevel[count($currentLevel) - 1]->attributes()->rgt);
}
}
return $xml->asXml();
}
示例4: delextrafields
public function delextrafields(Request $request, $location_id, $item_type)
{
$type = Itemtype::find($item_type);
$fields = $request->input();
$rootXML = new \SimpleXMLElement($type['extra_fields']);
//simplexml_load_string($type->extra_fields) or die("Error: Cannot create object");
//$bla = json_decode($request->input('data'),true);
//var_dump($request->input());
foreach ($fields as $field) {
$j = 0;
for ($x = 0; $x < $type->count; $x++) {
//$fields[] = strval($rootXML->field[$x]['name']);
if (strval($rootXML->field[$j]['name']) === $field) {
unset($rootXML->field[$j]);
$type->count = $type->count - 1;
$j = $j - 1;
}
$j = $j + 1;
}
}
// should also create a batch function to later remove all data from items_meta tables extra_values field
$type->extra_fields = $rootXML->asXml();
if ($type->count < 1) {
$type->extra_fields = null;
}
if ($type->save() === true) {
return response()->json(["Response" => "success"]);
} else {
return response()->json(["Response" => "fail"]);
}
}
示例5: listXmlAction
public function listXmlAction()
{
$baseStr = "<?xml version='1.0' standalone='yes'?><rows></rows>";
$xml = new SimpleXMLElement($baseStr);
$updateFile = new UpdateFile();
$updateFileIterator = $updateFile->getIteratorActive();
$alterTable = new AlterTable();
$channel = null;
$ctr = 1;
foreach ($updateFileIterator as $item) {
if ($channel === null || $channel != $item->channel) {
$channel = $item->channel;
$channelXml = $xml->addChild('row', $channel);
$channelXml->addAttribute('id', $ctr++);
$channelXml->addChild('cell', $channel);
}
$parent = $channelXml->addChild('row');
$parent->addAttribute('id', $item->updateFileId);
$parent->addChild('cell', $item->name . ' (v' . $item->version . ')');
$parent->addChild('cell', $item->status);
$parent->addChild('cell', '');
}
header('content-type: text/xml');
$this->view->content = $xml->asXml();
$this->render('list-xml');
}
示例6: XSLTProcessor
function __construct($src)
{
$this->xslt = new XSLTProcessor();
$this->xslt->registerPHPFunctions();
$this->xslt->importStylesheet($xml = new SimpleXMLElement('<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:php="http://php.net/xsl">
<xsl:output method="text" encoding="UTF-8"/>
<xsl:template match="/template-arguments">' . $this->compileFragment(strtr($src, array("<" => "<", ">" => ">", '"' => """, "'" => "'", "&" => "&"))) . '</xsl:template></xsl:stylesheet>'));
print $xml->asXml();
}
示例7: deleteItem
/**
* Delete row with id_item how reference
*/
function deleteItem()
{
$doc = new SimpleXMLElement('xml/blacklist.xml', null, true);
foreach ($doc->ITEM as $ITEM) {
if ($ITEM['ID'] == $this->id_item) {
$dom = dom_import_simplexml($ITEM);
$dom->parentNode->removeChild($dom);
}
}
echo $doc->asXml('xml/blacklist.xml');
}
示例8: actionIndex
public function actionIndex()
{
// $arrGoogle=array('google','Gmail','Chrome','Android');
// //第一次使用each取得当前键值对,并且将指针移到下一个位置
// $arrG=each($arrGoogle);
// print_r($arrG);
// $arrGmail=each($arrGoogle);
// print_r($arrGmail);
// $arrChrome=each($arrGoogle);
// print_r($arrChrome);
// $arrAndroid=each($arrGoogle);
// print_r($arrAndroid);
//当指针位于数组末尾再次执行函数each,如果是这样再次执行结果返回false
// $empty=each($arrGoogle);die();
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="GBK"?><DOCUMENT />');
header("Content-type: text/html; charset=utf-8");
include "simple_html_dom.php";
$html = file_get_html('http://www.ttpet.com/quanzhong/jinmao.html');
$item = $xml->addchild("item");
// Find all images
foreach ($html->find('dl.qz_inft ') as $element) {
/*echo $element;die();*/
/*echo $element->children(2);echo $element->children(3);die()*/
// $num1 = $item->addchild("name",$element->children(1)->plaintext);
$num1 = $item->addchild("alias", $element->children(2)->plaintext);
}
$num1 = $item->addchild("ename", $element->children(3)->plaintext);
// $num1 = $item->addchild("weight",$element->children(8)->plaintext);
// $num1 = $item->addchild("years",$element->children(9)->plaintext);
// $num1 = $item->addchild("place",$element->children(10)->plaintext);
// $num1 = $item->addchild("shape",$element->children(4)->plaintext);
// $num1 = $item->addchild("wool",$element->children(6)->plaintext);
$num1 = $item->addchild("function", $element->children(5)->plaintext);
// $num1 = $item->addchild("name",$element->plaintext);
// unset($num1);continue;
// $item->addchild("age",$element-next_sibling()->plaintext();
header("Content-type: text/xml");
echo $xml->asXml();
$xml->asXml("student.xml");
// die();
}
示例9: createColorLibrary
/**
* 添加颜色到颜色库
* @param $colorName
*/
function createColorLibrary($filename)
{
if (file_exists($filename)) {
$xml = simplexml_load_file($filename);
return $xml;
} else {
$xml = new SimpleXMLElement('<?xml version="1.0" encoding="utf-8"?><Colors />');
$xml->asXml($filename);
$colorXml = simplexml_load_file($filename);
return $colorXml;
}
}
示例10: handle
public function handle()
{
$result = $this->generateSoapXML($this->data);
$result = new SimpleXMLElement($result);
if ($this->wsdl_out == true) {
//header("Content-Type: application/xml; charset=utf-8");
//echo $result->asXml();
$tmpfile = tempnam(sys_get_temp_dir(), "wsdl");
$file = fopen($tmpfile, "w");
fwrite($file, $result->asXml());
fclose($file);
$server = new SoapServer($tmpfile);
foreach ($this->data as $value) {
$server->addFunction($value->funcName);
}
$server->handle();
unlink($tmpfile);
return;
} else {
echo $this->echoXML($result->asXml());
}
}
示例11: createXml
/**
* @param ProgrammeCondroid[] $programme
*/
private function createXml(array $programme)
{
$annotations = new \SimpleXMLElement('<annotations></annotations>');
foreach ($programme as $item) {
$node = $annotations->addChild('programme');
$node->addChild('pid', $item->pid);
$node->addChild('author', '<![CDATA[' . $item->author . ']]>');
$node->addChild('title', '<![CDATA[' . $item->title . ']]>');
$node->addChild('type', $item->type);
$node->addChild('program-line', '<![CDATA[' . $item->programLine . ']]>');
$node->addChild('location', $item->location);
$node->addChild('start-time', $item->startTime->format(DATE_ISO8601));
$node->addChild('end-time', $item->endTime->format(DATE_ISO8601));
$node->addChild('annotation', '<![CDATA[' . $item->annotation . ']]>');
}
return $annotations->asXml();
}
示例12: deleteFromMasterConfig
private static function deleteFromMasterConfig($strPluginName)
{
$oldContents = QFile::readFile(self::getMasterConfigFilePath());
$doc = new SimpleXMLElement($oldContents);
$found = false;
foreach ($doc as $plugin) {
if ($plugin->name == $strPluginName) {
$dom = dom_import_simplexml($plugin);
$dom->parentNode->removeChild($dom);
$found = true;
break;
}
}
$newContents = $doc->asXml();
$newContents = self::stripExtraNewlines($newContents);
QFile::writeFile(self::getMasterConfigFilePath(), $newContents);
return $found;
}
示例13: googlefixes
/**
* Clean up the xml file as google requires
* @param string $feed
*/
private function googlefixes($feed)
{
// Delete wrong attributes used by the Atom 1.0
$feed = str_replace(" type=\"html\"", "", $feed);
$feed = str_replace(" type=\"text\"", "", $feed);
// Delete some xml childs from the xml
$xmlfeed = new SimpleXMLElement($feed);
foreach ($xmlfeed->entry as $child) {
$target = $child->id;
if ($target) {
$dom = dom_import_simplexml($target);
$dom->parentNode->removeChild($dom);
}
}
$feed = $xmlfeed->asXml();
// removeChild method leave a blank line after the deletion of the xml child
$feed = preg_replace("/(^[\r\n]*|[\r\n]+)[\\s\t]*[\r\n]+/", "\n", $feed);
return $feed;
}
示例14: toXml
function toXml()
{
$baseStr = '<?xml version="1.0" standalone="yes"?><tree id="0"></tree>';
$xml = new SimpleXMLElement($baseStr);
$currentLevel = $xml;
$currentParent = 0;
$currentNode = null;
foreach ($this->_tree as $row) {
if ($currentParent != $row['parentId']) {
$currentLevel = $currentNode;
}
$node = $currentLevel->addChild('item');
$node->addAttribute('id', $row['locationId']);
$node->addAttribute('text', $row['name']);
$currentParent = $row['parentId'];
$currentNode = $node;
}
return $xml->asXml();
}
示例15: getPackageXml
/**
* Get string with XML content.
*
* @return string
*/
public function getPackageXml()
{
return $this->_packageXml->asXml();
}