本文整理汇总了PHP中SimpleXMLExtended::addAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP SimpleXMLExtended::addAttribute方法的具体用法?PHP SimpleXMLExtended::addAttribute怎么用?PHP SimpleXMLExtended::addAttribute使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SimpleXMLExtended
的用法示例。
在下文中一共展示了SimpleXMLExtended::addAttribute方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: saveTemplate
function saveTemplate($data)
{
My_Logger::log("in Ajax_TemplateEditorProcessor saveTemplate()");
$expected = array('filename', 'type', 'time', 'concepts', 'instructions', 'problem');
$filename = $this->get($data['filename']);
if (empty($filename)) {
throw new Exception('Missing Filename');
}
My_Logger::log("filename is " . $filename);
foreach ($expected as $field) {
$toCheck = $this->get($data[$field]);
if (empty($toCheck)) {
//if (empty($this->get($data[$field]))){
throw new Exception('Missing field: ' . $field);
}
}
//build xml
$xml = new SimpleXMLExtended('<question/>');
$xml->addAttribute('type', $this->get($data['type']));
$xml->addChild('estimated_time', $this->get($data['time']));
$concepts = $xml->addChild('concepts');
$concepts->addChild('concept', $this->get($data['concepts']));
$xml->addChild('difficulty', $this->get($data['difficulty']));
$xml->addChild('instructions', $this->get($data['instructions']));
//$xml->problem = null;
//$xml->problem->addCData($this->get($data['problem']));
$xml->addCData('problem', $this->get($data['problem']));
$sc = $xml->addChild('substitutions');
$subs = $this->get($data['s']);
if ($subs) {
foreach ($subs as $sd) {
if (empty($sd['name']) || empty($sd['value'])) {
continue;
}
$s = $sc->addCData('substitution', $sd['value']);
$s->addAttribute('val', $sd['name']);
}
}
$config = new Zend_Config_Ini(APPLICATION_PATH . "/configs/application.ini", APPLICATION_ENV);
$path = $config->xml->import_path;
$full_filename = $path . DIRECTORY_SEPARATOR . $filename;
My_Logger::log("Saving to {$full_filename}");
$xml->saveXML($full_filename);
chmod($full_filename, 0666);
return array('result' => 'success', 'msg' => "File '{$filename}' saved correctly");
}
示例2: array
echo "output dir = {$outputDir}<br/>";
$names = array();
// generate one testsuite for each run
$result = mysql_queryf("SELECT name,id FROM runs WHERE job_id = {$jobId};");
while ($run = mysql_fetch_array($result)) {
$names[$packageName . '.' . $run['name']]['runId'] = $run['id'];
}
foreach ($names as $name => $value) {
$runId = $value['runId'];
$xmlstr = "<?xml version='1.0' ?>\n<testsuite></testsuite>";
// get one testsuite for each useragent (mozilla 3.5, opera 10, ...)
$result = mysql_queryf("SELECT run_id,useragent_id,name,os FROM run_useragent LEFT OUTER JOIN useragents ON run_useragent.useragent_id = useragents.id WHERE run_id={$runId} AND status=2");
while ($runAtAgend = mysql_fetch_array($result)) {
$xml = new SimpleXMLExtended($xmlstr);
$testsuiteName = $name . '.' . str_replace('.', '-', $runAtAgend['name'] . " on " . $runAtAgend['os']);
$xml->addAttribute('name', $testsuiteName);
$value['useragents'][$runAtAgend['useragent_id']]['xml'] = $xml;
$value['useragents'][$runAtAgend['useragent_id']]['name'] = $testsuiteName;
}
// create on test foreach clientrun of user agent
foreach ($value['useragents'] as $userAgentId => $useragent) {
$xml = $useragent['xml'];
$errors = 0;
$tests = 0;
$failures = 0;
$sysout = '';
$result = mysql_queryf("SELECT fail,error,total,results,ip,useragent FROM run_client INNER JOIN clients ON run_client.client_id = clients.id WHERE useragent_id={$userAgentId} AND run_id={$runId}");
while ($runAtClient = mysql_fetch_array($result)) {
preg_match('/\\(.*\\)/', $runAtClient['useragent'], $matches);
$clientName = $runAtClient['ip'] . " " . $matches[0];
// create dummy testcases because some CI server like hudson count
示例3: _fillDevice
/**
* fill a xml element with atrributes from a disk device
*
* @param SimpleXmlExtended $mount Xml-Element
* @param DiskDevice $dev DiskDevice
* @param Integer $i counter
*
* @return Void
*/
private function _fillDevice(SimpleXMLExtended $mount, DiskDevice $dev, $i)
{
$mount->addAttribute('MountPointID', $i);
$mount->addAttribute('FSType', $dev->getFsType());
$mount->addAttribute('Name', $dev->getName());
$mount->addAttribute('Free', sprintf("%.0f", $dev->getFree()));
$mount->addAttribute('Used', sprintf("%.0f", $dev->getUsed()));
$mount->addAttribute('Total', sprintf("%.0f", $dev->getTotal()));
$mount->addAttribute('Percent', $dev->getPercentUsed());
if (PSI_SHOW_MOUNT_OPTION === true) {
if ($dev->getOptions() !== null) {
$mount->addAttribute('MountOptions', preg_replace("/,/", ", ", $dev->getOptions()));
}
}
if ($dev->getPercentInodesUsed() !== null) {
$mount->addAttribute('Inodes', $dev->getPercentInodesUsed());
}
if (PSI_SHOW_MOUNT_POINT === true) {
$mount->addAttribute('MountPoint', $dev->getMountPoint());
}
}
示例4: outputObject
/**
* @brief Create the XML output of the AREL Object and send it to the junaio server.
* @param ArelObject $oObject Object to be sent out
*/
public static function outputObject($oObject)
{
$object = new SimpleXMLExtended("<object></object>");
$object->addAttribute('id', (string) $oObject->getID());
if ($oObject->getTitle()) {
$object->addCData('title', $oObject->getTitle());
}
if ($oObject->getThumbnail()) {
$object->addCData('thumbnail', $oObject->getThumbnail());
}
if ($oObject->getIcon()) {
$object->addCData('icon', $oObject->getIcon());
}
//location
if ($oObject->getLocation()) {
$location = $object->addChild("location");
$oLocation = $oObject->getLocation();
try {
$location->addChild('lat', $oLocation[0]);
$location->addChild('lon', $oLocation[1]);
if (isset($oLocation[2])) {
$location->addChild('alt', $oLocation[2]);
} else {
$location->addChild('alt', 0);
}
} catch (Exception $e) {
return $e;
}
}
//popup
if ($oObject->getPopup()) {
$popup = $object->addChild("popup");
$oPopUp = $oObject->getPopup();
if ($oPopUp->getDescription()) {
$popup->addCData('description', $oPopUp->getDescription());
}
if ($oPopUp->getButtons()) {
$buttons = $popup->addChild("buttons");
$aButtons = $oPopUp->getButtons();
foreach ($aButtons as $oButton) {
$button = $buttons->addCData("button", $oButton[2]);
$button->addAttribute("id", $oButton[1]);
$button->addAttribute("name", $oButton[0]);
}
}
}
if ($oObject instanceof ArelObjectModel3D) {
//assets3D
$assets3D = $object->addChild("assets3d");
if ($oObject->getModel()) {
$assets3D->addCData('model', $oObject->getModel());
}
if ($oObject->getMovie()) {
$assets3D->addCData('movie', $oObject->getMovie());
}
if ($oObject->getTexture()) {
$assets3D->addCData('texture', $oObject->getTexture());
}
//transform
$transform = $assets3D->addChild("transform");
$oTransform = $oObject->getTransformParent();
if (isset($oTransform)) {
$transform->addAttribute("parent", $oTransform);
}
try {
//translation
$translation = $transform->addChild("translation");
$oTranslation = $oObject->getTranslation();
$translation->addChild("x", $oTranslation[0]);
$translation->addChild("y", $oTranslation[1]);
$translation->addChild("z", $oTranslation[2]);
//rotation
$rotation = $transform->addChild("rotation");
$oRotationElement = $oObject->getRotation();
$oRotation = $oRotationElement->getRotationValues();
$oRotationType = $oRotationElement->getRotationType();
$rotation->addAttribute("type", $oRotationType);
if ($oRotationType !== ArelRotation::ROTATION_MATRIX) {
$rotation->addChild("x", $oRotation[0]);
$rotation->addChild("y", $oRotation[1]);
$rotation->addChild("z", $oRotation[2]);
if ($oRotationType == ArelRotation::ROTATION_QUATERNION) {
$rotation->addChild("w", $oRotation[3]);
} else {
if ($oRotationType == ArelRotation::ROTATION_AXISANGLE) {
$rotation->addChild("angle", $oRotation[3]);
}
}
} else {
$rotation->addChild("m0", $oRotation[0]);
$rotation->addChild("m1", $oRotation[1]);
$rotation->addChild("m2", $oRotation[2]);
$rotation->addChild("m3", $oRotation[3]);
$rotation->addChild("m4", $oRotation[4]);
$rotation->addChild("m5", $oRotation[5]);
$rotation->addChild("m6", $oRotation[6]);
//.........这里部分代码省略.........
示例5: siteToXML
public function siteToXML(ModelObject $site)
{
$xml = new SimpleXMLExtended('<site/>');
foreach (array('Name', 'Description') as $key) {
$xml->addChild(StringUtils::underscore($key), $site->{$key});
}
if ($site->SiteID == 1) {
$xml->addAttribute('anchor', 'true');
}
$xml->addAttribute('slug', $site->Slug);
$xml->addChild('domain', $site->PublicDomain);
// $xml->addChild('domain_base_uri', '');
// $xml->addChild('domain_aliases', '');
// $xml->addChild('domain_redirects', '');
return $xml;
}
示例6: render
/**
* returns the XML string
*
* @return string
* @throws \Zend_Config_Exception
*/
public function render()
{
$xml = new SimpleXMLExtended('<' . $this->getRootElementName() . ' />');
foreach ($this->getRootElementAttributes() as $key => $value) {
$xml->addAttribute($key, $value);
}
if ($this->_config) {
$extends = $this->_config->getExtends();
$sectionName = $this->_config->getSectionName();
if (is_string($sectionName)) {
$child = $xml->addChild($sectionName);
$this->_addBranch($this->_config, $child, $xml);
} else {
foreach ($this->_config as $sectionName => $data) {
if (!$data instanceof \Zend_Config) {
$this->addChildConsiderCdata($xml, $sectionName, $data);
} else {
$child = $xml->addChild($sectionName);
if (isset($extends[$sectionName])) {
$child->addAttribute('zf:extends', $extends[$sectionName], \Zend_Config_Xml::XML_NAMESPACE);
}
$this->_addBranch($data, $child, $xml);
}
}
}
}
$dom = dom_import_simplexml($xml)->ownerDocument;
if ($encoding = $this->getEncoding()) {
$dom->encoding = $encoding;
}
$dom->formatOutput = $this->getFormatOutput();
$xmlString = $dom->saveXML();
return $xmlString;
}
示例7: backup
function backup()
{
$settings = Plugin::getAllSettings('backup_restore');
// All of the tablesnames that belong to Fresh CMS core.
$tablenames = array('layout', 'page', 'page_part', 'page_tag', 'permission', 'plugin_settings', 'setting', 'snippet', 'tag', 'user', 'user_permission');
// All fields that should be wrapped as CDATA
$cdata_fields = array('content', 'content_html');
// Setup XML for backup
$xmltext = '<?xml version="1.0" encoding="UTF-8"?><freshcms></freshcms>';
$xmlobj = new SimpleXMLExtended($xmltext);
$xmlobj->addAttribute('version', CMS_VERSION);
// Retrieve all database information for placement in XML backup
global $__CMS_CONN__;
Record::connection($__CMS_CONN__);
$lasttable = '';
// Generate XML file entry for each table
foreach ($tablenames as $tablename) {
$table = Record::query('SELECT * FROM ' . TABLE_PREFIX . $tablename);
while ($entry = $table->fetchObject()) {
if ($lasttable !== $tablename) {
$lasttable = $tablename;
$child = $xmlobj->addChild($tablename . 's');
}
$subchild = $child->addChild($tablename);
while (list($key, $value) = each($entry)) {
if ($key === 'password' && $settings['pwd'] === '0') {
$value = '';
}
if (in_array($key, $cdata_fields, true)) {
$subchild->addCData($key, $value);
} else {
$subchild->addChild($key, $value);
}
}
}
}
// Create the XML file
$file = $xmlobj->asXML();
$filename = 'freshcms-backup-' . date($settings['stamp']);
// Offer a plain XML file or a zip file for download
if ($settings['zip'] == '1') {
// Create a note file
$note = "---[ NOTES for {$filename}.xml ]---\n\n";
$note .= "This backup was created for a specific Fresh CMS version, please only restore it\n";
$note .= "on the same version.\n\n";
$note .= "When restoring a backup, upload the UNzipped XML file, not this zip file.\n\n";
$note .= 'Created on ' . date('Y-m-d') . ' at ' . date('H:i:s') . ' GTM ' . date('O') . ".\n";
$note .= 'Created with BackupRestore plugin version ' . BR_VERSION . "\n";
$note .= 'Created for Fresh CMS version ' . CMS_VERSION . "\n\n";
$note .= '---[ END NOTES ]---';
use_helper('Zip');
$zip = new Zip();
$zip->clear();
$zip->addFile($note, 'readme.txt');
$zip->addFile($file, $filename . '.xml');
$zip->download($filename . '.zip');
} else {
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: text/xml; charset=UTF-8');
header('Content-Disposition: attachment; filename=' . $filename . '.xml;');
header('Content-Transfer-Encoding: 8bit');
header('Content-Length: ' . strlen($file));
echo $file;
}
}
示例8: addCData
exit;
// Exit if accessed directly
}
$order = wc_get_order($order_id);
class SimpleXMLExtended extends SimpleXMLElement
{
public function addCData($cdata_text)
{
$node = dom_import_simplexml($this);
$no = $node->ownerDocument;
$node->appendChild($no->createCDATASection($cdata_text));
}
}
//Create SimpleXMLElement object
$xml = new SimpleXMLExtended('<?xml version="1.0" encoding="UTF-8"?><orders/>');
$xml->addAttribute('scheme', '2.0');
$mydata = $xml->addChild('order');
$orderID = $mydata->addAttribute('order_id', $order_id);
$task = $mydata->addChild('task');
$taskID = $task->addAttribute('id', $order_id);
$username = $task->username = NULL;
$username = $task->username->addCData('Hong Todd');
$bottlesize = $task->addChild('bottleSize', 10);
$printAmount = $task->addChild('printAmount', 10);
$array = array();
foreach ($order->get_items() as $item_id => $item) {
$rray = array('name' => $item['name'], 'qty' => $item['qty']);
$array[] = $rray;
}
foreach ($array as $key => $value) {
$result .= $value['name'] . " " . $value['qty'];
示例9: backup
function backup()
{
$settings = Plugin::getAllSettings('backup_restore');
// All of the tablesnames that belong to Wolf CMS core.
$tablenames = array();
if (strpos(DB_DSN, 'mysql') !== false) {
$sql = 'show tables';
}
if (strpos(DB_DSN, 'sqlite') !== false) {
$sql = 'SELECT name FROM SQLITE_MASTER WHERE type="table" ORDER BY name';
}
if (strpos(DB_DSN, 'pgsql') !== false) {
$sql = "select tablename from pg_tables where schemaname='public'";
}
Record::logQuery($sql);
$pdo = Record::getConnection();
$result = $pdo->query($sql);
while ($col = $result->fetchColumn()) {
$tablenames[] = $col;
}
// All fields that should be wrapped as CDATA
$cdata_fields = array('title', 'content', 'content_html');
// Setup XML for backup
$xmltext = '<?xml version="1.0" encoding="UTF-8"?><wolfcms></wolfcms>';
$xmlobj = new SimpleXMLExtended($xmltext);
$xmlobj->addAttribute('version', CMS_VERSION);
// Retrieve all database information for placement in XML backup
global $__CMS_CONN__;
Record::connection($__CMS_CONN__);
// Generate XML file entry for each table
foreach ($tablenames as $tablename) {
$table = Record::query('SELECT * FROM ' . $tablename);
$child = $xmlobj->addChild($tablename . 's');
while ($entry = $table->fetch(PDO::FETCH_ASSOC)) {
$subchild = $child->addChild($tablename);
foreach ($entry as $key => $value) {
if ($key == 'password' && $settings['pwd'] === '0') {
$value = '';
}
if (in_array($key, $cdata_fields, true)) {
$valueChild = $subchild->addCData($key, $value);
} else {
$valueChild = $subchild->addChild($key, str_replace('&', '&', $value));
}
if ($value === null) {
$valueChild->addAttribute('null', true);
}
}
}
}
// Add XML files entries for all files in upload directory
if ($settings['backupfiles'] == '1') {
$dir = realpath(FILES_DIR);
$this->_backup_directory($xmlobj->addChild('files'), $dir, $dir);
}
// Create the XML file
$file = $xmlobj->asXML();
$filename = 'wolfcms-backup-' . date($settings['stamp']) . '.' . $settings['extension'];
// Offer a plain XML file or a zip file for download
if ($settings['zip'] == '1') {
// Create a note file
$note = "---[ NOTES for {$filename} ]---\n\n";
$note .= "This backup was created for a specific Wolf CMS version, please only restore it\n";
$note .= "on the same version.\n\n";
$note .= "When restoring a backup, upload the UNzipped XML backup file, not this zip file.\n\n";
$note .= 'Created on ' . date('Y-m-d') . ' at ' . date('H:i:s') . ' GTM ' . date('O') . ".\n";
$note .= 'Created with BackupRestore plugin version ' . BR_VERSION . "\n";
$note .= 'Created for Wolf CMS version ' . CMS_VERSION . "\n\n";
$note .= '---[ END NOTES ]---';
use_helper('Zip');
$zip = new Zip();
$zip->clear();
$zip->addFile($note, 'readme.txt');
$zip->addFile($file, $filename);
$zip->download($filename . '.zip');
} else {
header('Pragma: public');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Cache-Control: private', false);
header('Content-Type: text/xml; charset=UTF-8');
header('Content-Disposition: attachment; filename=' . $filename . ';');
header('Content-Transfer-Encoding: 8bit');
header('Content-Length: ' . strlen($file));
echo $file;
}
}