本文整理汇总了PHP中DOMDocument::createElement方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument::createElement方法的具体用法?PHP DOMDocument::createElement怎么用?PHP DOMDocument::createElement使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::createElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: serialize
/**
* (non-PHPdoc)
* @see lib/Faett/Channel/Serializer/Interfaces/Faett_Channel_Serializer_Interfaces_Serializer#serialize()
*/
public function serialize()
{
try {
// initialize a new DOM document
$doc = new DOMDocument('1.0', 'UTF-8');
// create new namespaced root element
$a = $doc->createElementNS($this->_namespace, 'a');
// add the schema to the root element
$a->setAttributeNS('http://www.w3.org/2001/XMLSchema-instance', 'xsi:schemaLocation', 'http://pear.php.net/dtd/rest.allcategories http://pear.php.net/dtd/rest.allcategories.xsd');
// create an element for the channel's name
$ch = $doc->createElement('ch');
$ch->nodeValue = Mage::helper('channel')->getChannelName();
// append the element with the channel's name to the root element
$a->appendChild($ch);
// load the product's attributes
$attributes = $this->_category->getSelectOptions();
// iterate over the channel's categories
foreach ($attributes as $attribute) {
$c = $doc->createElement('c');
$c->setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href', '/channel/index/c/' . $attribute . '/info.xml');
$c->nodeValue = $attribute;
// append the XLink to the root element
$a->appendChild($c);
}
// append the root element to the DOM tree
$doc->appendChild($a);
// return the XML document
return $doc->saveXML();
} catch (Exception $e) {
return $e->getMessage();
}
}
示例2: getMessage
/**
*
* @return string
*/
public function getMessage()
{
if (empty($this->_jobTraining)) {
return '';
}
$this->_dom = new DOMDocument();
$classMessage = 'alert ';
$divFluid = $this->_dom->createElement('div');
$divMessage = $this->_dom->createElement('div');
$divFluid->setAttribute('class', 'row-fluid');
if ($this->_jobTraining->status != 1) {
$classMessage .= 'alert-error';
$iconClass = 'icon-remove-sign';
$alertText = ' Atensaun ';
$message = ' Job Training ' . ($this->_jobTraining->status == 2 ? 'Kansela' : 'Taka') . ' tiha ona, La bele halo Atualizasaun.';
} else {
$iconClass = 'icon-ok-sign';
$classMessage .= 'alert-success';
$alertText = '';
$message = ' Job Training Loke, então bele halo Atualizasaun.';
}
$divMessage->setAttribute('class', $classMessage);
$strong = $this->_dom->createElement('strong');
$i = $this->_dom->createElement('i');
$i->setAttribute('class', $iconClass);
$strong->appendChild($i);
$strong->appendChild($this->_dom->createTextNode($alertText));
$divMessage->appendChild($strong);
$divMessage->appendChild($this->_dom->createTextNode($message));
$divFluid->appendChild($divMessage);
$this->_dom->appendChild($divFluid);
return $this->_dom->saveHTML();
}
示例3: load
/**
* Load DOMDocument from xml string
*
* @param string $source xml string
* @param string $contentType
* @return DOMDocument|FALSE
*/
public function load($source, $contentType)
{
if (is_object($source) && $source instanceof PDOStatement) {
$source->setFetchMode(PDO::FETCH_NUM);
$columnCount = $source->columnCount();
$columns = array();
for ($i = 0; $i < $columnCount; $i++) {
$columnData = $source->getColumnMeta($i);
$columns[$i] = array('name' => $this->_normalizeColumnName($columnData['name']), 'type' => $this->_getNodeType($columnData));
}
$dom = new DOMDocument();
$dom->formatOutput = TRUE;
$dom->appendChild($rootNode = $dom->createElement($this->_tagNameRoot));
foreach ($source as $row) {
$rootNode->appendChild($recordNode = $dom->createElement($this->_tagNameRecord));
foreach ($row as $columnId => $value) {
switch ($columns[$columnId]['type']) {
case self::ATTRIBUTE_VALUE:
$recordNode->setAttribute($columns[$columnId]['name'], $value);
break;
default:
$recordNode->appendChild($valueNode = $dom->createElement($columns[$columnId]['name'], $value));
break;
}
}
}
return $dom;
}
return FALSE;
}
示例4: describeAnalysis
protected function describeAnalysis(Analysis $analysis, array $options = array())
{
$output = $options['output'];
$xml = new \DOMDocument('1.0', 'UTF-8');
$xpath = new \DOMXPath($xml);
$xml->formatOutput = true;
$xml->preserveWhiteSpace = true;
$pmd = $xml->createElement('pmd');
$pmd->setAttribute('timestamp', $analysis->getEndAt()->format('c'));
$xml->appendChild($pmd);
foreach ($analysis->getViolations() as $violation) {
/**
* @var $violation \SensioLabs\Insight\Sdk\Model\Violation
*/
$filename = $violation->getResource();
$nodes = $xpath->query(sprintf('//file[@name="%s"]', $filename));
if ($nodes->length > 0) {
$node = $nodes->item(0);
} else {
$node = $xml->createElement('file');
$node->setAttribute('name', $filename);
$pmd->appendChild($node);
}
$violationNode = $xml->createElement('violation', $violation->getMessage());
$node->appendChild($violationNode);
$violationNode->setAttribute('beginline', $violation->getLine());
$violationNode->setAttribute('endline', $violation->getLine());
$violationNode->setAttribute('rule', $violation->getTitle());
$violationNode->setAttribute('ruleset', $violation->getCategory());
$violationNode->setAttribute('priority', $this->getPriority($violation));
}
$output->writeln($xml->saveXML());
}
示例5: __call
public function __call($method, $arguments)
{
$dom = new DOMDocument('1.0', 'UTF-8');
$element = $dom->createElement('method');
$element->setAttribute('name', $method);
foreach ($arguments as $argument) {
$child = $dom->createElement('argument');
$textNode = $dom->createTextNode($argument);
$child->appendChild($textNode);
$element->appendChild($child);
}
$dom->appendChild($element);
$data = 'service=' . $dom->saveXML();
$params = array('http' => array('method' => 'POST', 'content' => $data));
$ctx = stream_context_create($params);
$fp = @fopen($this->server, 'rb', false, $ctx);
if (!$fp) {
throw new Exception('Problem with URL');
}
$response = @stream_get_contents($fp);
if ($response === false) {
throw new Exception("Problem reading data from {$this->server}");
}
$dom = new DOMDocument(null, 'UTF-8');
$dom->loadXML($response);
$result = $dom->childNodes->item(0)->childNodes->item(0)->nodeValue;
$type = $dom->childNodes->item(0)->childNodes->item(1)->nodeValue;
settype($result, $type);
return $result;
}
示例6: getAsElem
/**
* Get the constraint as a DOMElement object.
*
* @param DOMDocument $dom The DOMDocument object with which to create the element.
*/
public function getAsElem($dom)
{
$constElem = $dom->createElement('constraint');
$constElem->setAttribute('name', $this->name);
$valElem = $dom->createElement('value');
$elemElem = $dom->createElement('element');
$elemElem->setAttribute('ns', $this->ns);
$elemElem->setAttribute('name', $this->elem);
$valElem->appendChild($elemElem);
if ($this->attr) {
$attrElem = $dom->createElement('attribute');
$attrElem->setAttribute('ns', $this->attrNs);
$attrElem->setAttribute('name', $this->attr);
$valElem->appendChild($attrElem);
}
$this->addTermOptions($dom, $valElem);
$this->addFragmentScope($dom, $valElem);
$constElem->appendChild($valElem);
/* <constraint name='flavor'>
<value>
<element ns='http://example.com' name='flavor-descriptor'/>
</value>
</constraint> */
return $constElem;
}
示例7: setChild
/**
* Sets a child on the given DOMDocument
* Returns true if a child was set, false if not
*
* @param \DOMElement $xml
* @param mixed $value
* @param string $variable
* @param array $options
*
* @return boolean
*/
protected function setChild(\DOMElement $xml, $value, $variable, $options)
{
if (null === $value) {
return false;
}
switch ($options['type']) {
case 'string':
case 'integer':
$element = $this->dom->createElement($variable, $value);
break;
case 'boolean':
$element = $this->dom->createElement($variable, $this->visitBoolean($value));
break;
case 'datetime':
$element = $this->dom->createElement($variable, $this->visitDatetime($value));
break;
default:
if (class_exists($options['type'])) {
// We mapped to an existing class
$element = $this->visitModel($value);
} elseif ($this->isArrayType($options['type'], $arrayType, $keepKey)) {
// We mapped to an array<type>
$element = $this->dom->createElement($variable);
foreach ($value as $key => $val) {
$key = $keepKey ? $key : $options['key'];
$this->setChild($element, $val, $key, ['type' => $arrayType]);
}
} else {
// A type we can't handle
return false;
}
}
$xml->appendChild($element);
return true;
}
示例8: _future_serializeAsXml
/**
* @author Zack Douglas <zack@zackerydouglas.info>
*/
private function _future_serializeAsXml($value, $node = null, $dom = null)
{
if (!$dom) {
$dom = new \DOMDocument();
}
if (!$node) {
if (!is_object($value)) {
$node = $dom->createElement('response');
$dom->appendChild($node);
} else {
$node = $dom;
}
}
if (is_object($value)) {
$objNode = $dom->createElement(get_class($value));
$node->appendChild($objNode);
$this->_future_serializeObjectAsXml($value, $objNode, $dom);
} else {
if (is_array($value)) {
$arrNode = $dom->createElement('array');
$node->appendChild($arrNode);
$this->_future_serializeArrayAsXml($value, $arrNode, $dom);
} else {
if (is_bool($value)) {
$node->appendChild($dom->createTextNode($value ? 'TRUE' : 'FALSE'));
} else {
$node->appendChild($dom->createTextNode($value));
}
}
}
return array($node, $dom);
}
示例9: action_index
public function action_index()
{
if (!file_exists(DOCROOT . $this->sitemap_directory_base)) {
throw new HTTP_Exception_404();
}
$this->site_code = ORM::factory('site', $this->request->site_id)->code;
$this->sitemap_directory = $this->sitemap_directory_base . DIRECTORY_SEPARATOR . $this->site_code;
$this->response->headers('Content-Type', 'text/xml')->headers('cache-control', 'max-age=0, must-revalidate, public')->headers('expires', gmdate('D, d M Y H:i:s', time()) . ' GMT');
try {
$dir = new DirectoryIterator(DOCROOT . $this->sitemap_directory);
$xml = new DOMDocument('1.0', Kohana::$charset);
$xml->formatOutput = TRUE;
$root = $xml->createElement('sitemapindex');
$root->setAttribute('xmlns', 'http://www.sitemaps.org/schemas/sitemap/0.9');
$xml->appendChild($root);
foreach ($dir as $fileinfo) {
if ($fileinfo->isDot() or $fileinfo->isDir()) {
continue;
}
$_file_path = str_replace(DOCROOT, '', $fileinfo->getPathName());
$_file_url = $this->domain . '/' . str_replace(DIRECTORY_SEPARATOR, '/', $_file_path);
$sitemap = $xml->createElement('sitemap');
$root->appendChild($sitemap);
$sitemap->appendChild(new DOMElement('loc', $_file_url));
$_last_mod = Sitemap::date_format($fileinfo->getCTime());
$sitemap->appendChild(new DOMElement('lastmod', $_last_mod));
}
} catch (Exception $e) {
echo Debug::vars($e->getMessage());
die;
}
echo $xml->saveXML();
}
示例10: _buildTransaction
private function _buildTransaction($action, HpsCheck $check, $amount, $clientTransactionId = null)
{
$amount = HpsInputValidation::checkAmount($amount);
if ($check->secCode == HpsSECCode::CCD && ($check->checkHolder == null || $check->checkHolder->checkName == null)) {
throw new HpsInvalidRequestException(HpsExceptionCodes::MISSING_CHECK_NAME, 'For SEC code CCD, the check name is required', 'check_name');
}
$xml = new DOMDocument();
$hpsTransaction = $xml->createElement('hps:Transaction');
$hpsCheckSale = $xml->createElement('hps:CheckSale');
$hpsBlock1 = $xml->createElement('hps:Block1');
$hpsBlock1->appendChild($xml->createElement('hps:Amt', sprintf("%0.2f", round($amount, 3))));
$hpsBlock1->appendChild($this->_hydrateCheckData($check, $xml));
$hpsBlock1->appendChild($xml->createElement('hps:CheckAction', $action));
$hpsBlock1->appendChild($xml->createElement('hps:SECCode', $check->secCode));
if ($check->checkType != null) {
$hpsBlock1->appendChild($xml->createElement('hps:CheckType', $check->checkType));
}
$hpsBlock1->appendChild($xml->createElement('hps:DataEntryMode', $check->dataEntryMode));
if ($check->checkHolder != null) {
$hpsBlock1->appendChild($this->_hydrateConsumerInfo($check, $xml));
}
$hpsCheckSale->appendChild($hpsBlock1);
$hpsTransaction->appendChild($hpsCheckSale);
return $this->_submitTransaction($hpsTransaction, 'CheckSale', $clientTransactionId);
}
示例11: get
static function get($jid, $start = false, $end = false, $limit = false)
{
$dom = new \DOMDocument('1.0', 'UTF-8');
$query = $dom->createElementNS('urn:xmpp:mam:0', 'query');
$x = $dom->createElementNS('jabber:x:data', 'x');
$query->appendChild($x);
$field_type = $dom->createElement('field');
$field_type->setAttribute('var', 'FORM_TYPE');
$field_type->appendChild($dom->createElement('value', 'urn:xmpp:mam:0'));
$x->appendChild($field_type);
$field_with = $dom->createElement('field');
$field_with->setAttribute('var', 'with');
$field_with->appendChild($dom->createElement('value', $jid));
$x->appendChild($field_with);
if ($start) {
$field_start = $dom->createElement('field');
$field_start->setAttribute('var', 'start');
$field_start->appendChild($dom->createElement('value', date('Y-m-d\\TH:i:s\\Z', $start + 1)));
$x->appendChild($field_start);
}
if ($end) {
$field_end = $dom->createElement('field');
$field_end->setAttribute('var', 'end');
$field_end->appendChild($dom->createElement('value', date('Y-m-d\\TH:i:s\\Z', $end + 1)));
$x->appendChild($field_end);
}
if ($limit) {
$field_limit = $dom->createElement('field');
$field_limit->setAttribute('var', 'limit');
$field_limit->appendChild($dom->createElement($limit));
$x->appendChild($field_limit);
}
$xml = \Moxl\API::iqWrapper($query, null, 'set');
\Moxl\API::request($xml);
}
示例12: createXmlElement
public function createXmlElement(DOMDocument $xmlDoc)
{
if (!$xmlDoc instanceof DOMDocument) {
throw new Exception('', self::ERROR_INVALID_PARAMETER);
}
$xmlItemElem = $xmlDoc->createElement('item');
if ($this->code == null || $this->name == null || $this->measurment == null || $this->quantity == null || $this->price == null || $this->vat == null) {
throw new Exception('Invalid property', self::ERROR_INVALID_PROPERTY);
}
$xmlElem = $xmlDoc->createElement('code');
$xmlElem->appendChild($xmlDoc->createCDATASection(urlencode($this->code)));
$xmlItemElem->appendChild($xmlElem);
$xmlElem = $xmlDoc->createElement('name');
$xmlElem->appendChild($xmlDoc->createCDATASection(urlencode($this->name)));
$xmlItemElem->appendChild($xmlElem);
$xmlElem = $xmlDoc->createElement('measurment');
$xmlElem->appendChild($xmlDoc->createCDATASection(urlencode($this->measurment)));
$xmlItemElem->appendChild($xmlElem);
$xmlElem = $xmlDoc->createElement('quantity');
$xmlElem->nodeValue = $this->quantity;
$xmlItemElem->appendChild($xmlElem);
$xmlElem = $xmlDoc->createElement('price');
$xmlElem->nodeValue = $this->price;
$xmlItemElem->appendChild($xmlElem);
$xmlElem = $xmlDoc->createElement('vat');
$xmlElem->nodeValue = $this->vat;
$xmlItemElem->appendChild($xmlElem);
return $xmlItemElem;
}
示例13: render
public function render($caption_set, $file = false)
{
$dom = new \DOMDocument("1.0");
$dom->formatOutput = true;
$root = $dom->createElement('tt');
$dom->appendChild($root);
$body = $dom->createElement('body');
$root->appendChild($body);
$xmlns = $dom->createAttribute('xmlns');
$xmlns->appendChild($dom->createTextNode('http://www.w3.org/ns/ttml'));
$root->appendChild($xmlns);
$div = $dom->createElement('div');
$body->appendChild($div);
foreach ($caption_set->captions() as $index => $caption) {
$entry = $dom->createElement('p');
$from = $dom->createAttribute('begin');
$from->appendChild($dom->createTextNode(DfxpHelper::time_to_string($caption->start())));
$entry->appendChild($from);
$to = $dom->createAttribute('end');
$to->appendChild($dom->createTextNode(DfxpHelper::time_to_string($caption->end())));
$entry->appendChild($to);
$entry->appendChild($dom->createCDATASection($caption->text()));
$div->appendChild($entry);
}
if ($file) {
return file_put_contents($file, $dom->saveXML());
} else {
return $dom->saveHTML();
}
}
示例14: unequalObjectsProvider
public function unequalObjectsProvider()
{
$dom = new \DOMDocument();
$element1 = $dom->createElement('foo', 'bar');
$element2 = $dom->createElement('foo', 'baz');
return array(array(new \StdClass(), new TestClass()), array(new TestClass('foo'), new TestClass('bar')), array(new TestClass(new \StdClass()), new TestClass(new TestClass())), array(new TestClass(new TestClass('foo')), new TestClass(new TestClass('bar'))), array(new TestClass($element1), new TestClass($element2)));
}
示例15: createRss
function createRss()
{
$dom = new DOMDocument("1.0", "utf-8");
$dom->formatOutput = true;
$dom->preserveWhiteSpace = false;
$rss = $dom->createElement("rss");
$dom->appendChild($rss);
$version = $dom->createAttribute("version");
$version->value = '2.0';
$rss->appendChild($version);
$channel = $dom->createElement("channel");
$rss->appendChild($channel);
$title = $dom->createElement("title", self::RSS_TITLE);
$channel->appendChild($title);
$link = $dom->createElement("link", self::RSS_LINK);
$channel->appendChild($link);
$items = $this->getNews();
foreach ($items as $item) {
$rssItem = $dom->createElement("item");
$nTitle = $dom->createElement("title", $item["title"]);
$nLink = $dom->createElement("link", $item["source"]);
$nDesc = $dom->createElement("description", $item["description"]);
$nPub = $dom->createElement("pubYear", $item["datetime"]);
$nCategory = $dom->createElement("category", $item["category"]);
$rssItem->appendChild($nTitle);
$rssItem->appendChild($nLink);
$rssItem->appendChild($nDesc);
$rssItem->appendChild($nPub);
$rssItem->appendChild($nCategory);
$channel->appendChild($rssItem);
}
$dom->save(self::RSS_NAME);
}