当前位置: 首页>>代码示例>>PHP>>正文


PHP DomDocument::createElement方法代码示例

本文整理汇总了PHP中DomDocument::createElement方法的典型用法代码示例。如果您正苦于以下问题:PHP DomDocument::createElement方法的具体用法?PHP DomDocument::createElement怎么用?PHP DomDocument::createElement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在DomDocument的用法示例。


在下文中一共展示了DomDocument::createElement方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: DomDocument

 function props_to_xml()
 {
     # make the source xml
     # make doc and root
     $xml = new DomDocument();
     $root = $xml->createElement('request');
     $root->setAttribute('controller', params('controller'));
     $root->setAttribute('action', params('action'));
     $root = $xml->appendChild($root);
     # unpack the props into xml
     foreach ($this->props as $k => $v) {
         # if it will become xml, do that, otherwise make a dumb tag
         if (is_object($v) && method_exists($v, 'to_xml')) {
             $obj_xml = $v->to_xml(array(), true, true);
             $obj_xml = $xml->importNode($obj_xml->documentElement, true);
             $root->appendChild($obj_xml);
         } else {
             $node = $xml->createElement($k);
             if (strpos($v, '<') !== false || strpos($v, '>') !== false || strpos($v, '&') !== false) {
                 $cdata = $xml->createCDATASection($v);
             } else {
                 $cdata = $xml->createTextNode($v);
             }
             $node->appendChild($cdata);
             $node = $root->appendChild($node);
         }
     }
     return $xml;
 }
开发者ID:brysonian,项目名称:Saint,代码行数:29,代码来源:AbstractView.php

示例2: getForm

 /**
  * Generate the form. The dates are not fixed, so we can't write an XML file for this.
  * Each date has a checkbox, defining whether the leader is available (ticked) or not
  * TODO: Display weekends and bank holidays (bank holidays currently not in database)
  */
 public function getForm($data = array(), $loadData = true)
 {
     if (!isset($this->form)) {
         // Looks like I have to generate the XML for the form?! WTF? Hurr durr OOP is hard for our programmer users durr.
         $XMLDoc = new DomDocument("1.0", "UTF-8");
         $formXML = $XMLDoc->createElement("form");
         $formXML->setAttribute("name", "manageavailability");
         $XMLDoc->appendChild($formXML);
         $fieldsetXML = $XMLDoc->createElement("fieldset");
         $fieldsetXML->setAttribute("name", "availability");
         $formXML->appendChild($fieldsetXML);
         $progNumXML = $XMLDoc->createElement("field");
         $progNumXML->setAttribute("type", "hidden");
         $progNumXML->setAttribute("name", "programmeid");
         $progNumXML->setAttribute("default", $this->programme->id);
         $fieldsetXML->appendChild($progNumXML);
         foreach ($this->programme->getLeaderAvailability($this->leader->id) as $date => $available) {
             $field = $XMLDoc->createElement("field");
             $field->setAttribute("type", "checkbox");
             $field->setAttribute("name", "availability_" . $date);
             $field->setAttribute("label", strftime("%A %e %B %Y", $date));
             $field->setAttribute("value", 1);
             $field->setAttribute("default", $available ? 1 : 0);
             $fieldsetXML->appendChild($field);
         }
         $this->form = $this->loadForm("com_swg_leaderutils.manageavailability", $XMLDoc->saveXML(), array('control' => 'jform', 'load_data' => false));
     }
     return $this->form;
 }
开发者ID:SheffieldWalkingGroup,项目名称:swgwebsite,代码行数:34,代码来源:manageavailability.php

示例3: create_xml_droits

function create_xml_droits($array_section)
{
    $dom_document = new DomDocument("1.0", "UTF-8");
    $dom_document->formatOutput = true;
    $root = $dom_document->createElement("droits");
    $root = $dom_document->appendChild($root);
    foreach ($array_section as $nom_section => $droits) {
        $section = $dom_document->createElement("section");
        $section->setAttribute("name", $nom_section);
        $section = $root->appendChild($section);
        foreach ($droits as $nom_droit => $type_droit) {
            $droit = $dom_document->createElement("droit");
            $droit = $section->appendChild($droit);
            $nom = $dom_document->createElement("name");
            $nom = $droit->appendChild($nom);
            $textNom = $dom_document->createTextNode($nom_droit);
            $textNom = $nom->appendChild($textNom);
            $type = $dom_document->createElement("type");
            $type = $droit->appendChild($type);
            $textType = $dom_document->createTextNode($type_droit);
            $textType = $type->appendChild($textType);
        }
    }
    $dom_document->save(PATH_ROOT . 'inc/droits.xml');
}
开发者ID:shiooooooookun,项目名称:Nouweo_PHP,代码行数:25,代码来源:create_xml_droits.php

示例4: getXmlNapojak

function getXmlNapojak()
{
    $d = new DomDocument('1.0', 'utf-8');
    $root_e = $d->createElement('napojak');
    foreach (MyDB::getInstance()->getResults(MyDB::getQuery(SELECT_NAPOJAK_KAT)) as $kat) {
        $kat_e = $d->createElement('kategorie');
        $kat_e->setAttribute('id', $kat['id']);
        $kat_e->setAttribute('nazev', $kat['nazev']);
        $kat_e->setAttribute('popis', $kat['popis']);
        $param = array(':kat_id' => $kat['id']);
        foreach (MyDB::getInstance()->getParamResults(MyDB::getQuery(SELECT_NAPOJAK), $param) as $row) {
            $item_e = $d->createElement('item');
            $item_e->setAttribute('id', $row['id']);
            $item_e->setAttribute('nazev', $row['nazev']);
            $item_e->setAttribute('popis', $row['popis']);
            $item_e->setAttribute('cena', $row['cena']);
            $en = (bool) $row['en'] ? "true" : "false";
            $item_e->setAttribute('en', $en);
            $kat_e->appendChild($item_e);
        }
        $root_e->appendChild($kat_e);
    }
    $d->appendChild($root_e);
    return $d->saveXML();
}
开发者ID:zcsevcik,项目名称:edu,代码行数:25,代码来源:napojak.php

示例5: convertArrayToXml

 /**
  * Convert an Array to XML
  * @param string $root_node - name of the root node to be converted
  * @param array $data - array to be converted
  * @throws \Exception
  * @return \DOMNode
  */
 protected function convertArrayToXml($root_node, $data = array())
 {
     if (!$this->isValidTagName($root_node)) {
         throw new \Exception('Array to XML Conversion - Illegal character in element name: ' . $root_node);
     }
     $node = $this->xml->createElement($root_node);
     if (is_scalar($data)) {
         $node->appendChild($this->xml->createTextNode($this->bool2str($data)));
     }
     if (is_array($data)) {
         foreach ($data as $key => $value) {
             $this->current_node_name = $root_node;
             $key = is_numeric($key) ? Inflector::singularize($this->current_node_name) : $key;
             $node->appendChild($this->convertArrayToXml($key, $value));
             unset($data[$key]);
         }
     }
     if (is_object($data)) {
         // Catch toString objects, and datetime. Note Closure's will fall into here
         if (method_exists($data, '__toString')) {
             $node->appendChild($this->xml->createTextNode($data->__toString()));
         } elseif ($data instanceof \DateTime) {
             $node->appendChild($this->xml->createTextNode($data->format(\DateTime::ISO8601)));
         } else {
             throw new \Exception('Invalid data type used in Array to XML conversion. Must be object of \\DateTime or implement __toString()');
         }
     }
     return $node;
 }
开发者ID:leedavis81,项目名称:drest-common,代码行数:36,代码来源:Xml.php

示例6: DomDocument

 function __doRequest($request, $location, $action, $version)
 {
     $dom = new DomDocument('1.0', 'UTF-8');
     $dom->preserveWhiteSpace = false;
     $dom->loadXML($request);
     $hdr = $dom->createElement('soapenv:Header');
     $secNode = $dom->createElement("wsse:Security");
     $secNode->setAttribute("soapenv:mustUnderstand", "1");
     $secNode->setAttribute("xmlns:wsse", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");
     $usernameTokenNode = $dom->createElement("wsse:UsernameToken");
     $usernameTokenNode->setAttribute("wsu:Id", "UsernameToken-1");
     $usernameTokenNode->setAttribute("xmlns:wsu", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");
     $usrNode = $dom->createElement("wsse:Username");
     $usrNode->appendChild($dom->createTextNode(WS_USER));
     $pwdNode = $dom->createElement("wsse:Password");
     $pwdNode->setAttribute("Type", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText");
     $pwdNode->appendchild($dom->createTextnode(WS_PWD));
     $usernameTokenNode->appendChild($usrNode);
     $usernameTokenNode->appendChild($pwdNode);
     $secNode->appendChild($usernameTokenNode);
     $hdr->appendChild($secNode);
     $dom->documentElement->insertBefore($hdr, $dom->documentElement->firstChild);
     $request = $dom->saveXML();
     $request = str_replace("SOAP-ENV", "soapenv", $request);
     $request = str_replace("ns1", "cgt", $request);
     $request = str_replace('<?xml version="1.0" encoding="UTF-8"?>', '', $request);
     //  echo "Este es el nuevo XML: " . print_r($request, true);
     return parent::__doRequest($request, $location, $action, $version);
 }
开发者ID:vallejos,项目名称:samples,代码行数:29,代码来源:ContentGatewayBilling.php

示例7: buildXml

 /**
  * Build the validate address request
  * @internal
  * @return string
  * @throws \SimpleUPS\Api\MissingParameterException
  */
 public function buildXml()
 {
     if ($this->getShipment()->getDestination() == null) {
         throw new MissingParameterException('Shipment destination is missing');
     }
     $dom = new \DomDocument('1.0');
     $dom->formatOutput = $this->getDebug();
     $dom->appendChild($ratingRequest = $dom->createElement('RatingServiceSelectionRequest'));
     $addressRequestLang = $dom->createAttribute('xml:lang');
     $addressRequestLang->value = parent::getXmlLang();
     $ratingRequest->appendChild($request = $dom->createElement('Request'));
     $request->appendChild($transactionReference = $dom->createElement('TransactionReference'));
     $transactionReference->appendChild($dom->createElement('CustomerContext', $this->getCustomerContext()));
     $request->appendChild($dom->createElement('RequestAction', 'Rate'));
     $request->appendChild($dom->createElement('RequestOption', 'Shop'));
     //@todo test with "Rate" as setting to determine difference
     $ratingRequest->appendChild($pickupType = $dom->createElement('PickupType'));
     $pickupType->appendChild($shipmentType = $dom->createElement('Code', $this->getPickupType()));
     if ($this->getRateType() != null) {
         $ratingRequest->appendChild($customerClassification = $dom->createElement('CustomerClassification'));
         $customerClassification->appendChild($dom->createElement('Code', $this->getRateType()));
     }
     // Shipment
     $shipment = $this->getShipment();
     $shipment->setShipper(UPS::getShipper());
     $ratingRequest->appendChild($shipment->toXml($dom));
     $xml = parent::buildAuthenticationXml() . $dom->saveXML();
     return $xml;
 }
开发者ID:bkuhl,项目名称:simple-ups,代码行数:35,代码来源:Request.php

示例8: teste

 function teste()
 {
     $xml = new DomDocument("1.0", "UTF-8");
     /*
     $container = $xml->createElement('container', 'tkjasdkfjal');
     $container = $xml->appendChild($container);
     
     
     $sale = $xml->createElement('sale');
     $sale = $container->appendChild($sale);
     
     
     $item = $xml->createElement('item', 'Television');
     $item = $sale->appendChild($item);
     
     $price = $xml->createElement('price', '$100');
     $price = $sale->appendChild($price);
     */
     $cadastro = $xml->createElement('Cadastro');
     $cadastro = $xml->appendChild($cadastro);
     $pessoa = $xml->createElement('Pessoa');
     $pessoa = $cadastro->appendChild($pessoa);
     $nome = $xml->createElement('nome', 'Rodrigo');
     $pessoa->appendChild($nome);
     $situacao = $xml->createElement('situacao', 'fudido');
     $pessoa->appendChild($situacao);
     $xml->FormatOutput = true;
     $string_value = $xml->saveXML();
     $xml->save('xml/teste.xml');
     echo 'xml criado, chupa mundo';
     exit;
     //$xml = Xml::build('<example>text</example>', array('app/teste.xml'));
     //exit;
 }
开发者ID:rodrigofigueira,项目名称:leste_homolog,代码行数:34,代码来源:TestesxmlController.php

示例9: _toHtml

 public function _toHtml()
 {
     $this->_checkRequired();
     $info = $this->getInfo();
     $certain = $info['certain'];
     $dom = new DomDocument();
     $dom->preserveWhitespace = false;
     $block = $dom->createElement('block');
     $attr = $dom->createAttribute('type');
     $attr->value = $this->getAlias();
     $block->appendChild($attr);
     $dom->appendChild($block);
     $output = simplexml_load_string('<block />');
     foreach ($certain as $method) {
         $block->appendChild($dom->createComment("\n     " . $this->_getDocumentation($method) . "\n  "));
         $dom_action = $dom->createElement('action');
         $block->appendChild($dom_action);
         $dom_attr = $dom->createAttribute('method');
         $dom_attr->value = $method->getName();
         $dom_action->appendChild($dom_attr);
         $this->addParamsToDomActionNodeFromReflectionMethod($dom, $dom_action, $method);
         //$action = $this->addParamsToActionNodeFromReflectionMethod($action, $method);
     }
     $dom->formatOutput = true;
     return $this->_extraXmlFormatting($dom->saveXml());
 }
开发者ID:itmyprofession,项目名称:Pulsestorm,代码行数:26,代码来源:Action.php

示例10: toXml

 /**
  * Convert a tree array (with depth) into a hierarchical XML string.
  *
  * @param $nodes|array   Array with depth value.
  *
  * @return string
  */
 public function toXml(array $nodes)
 {
     $xml = new DomDocument('1.0');
     $xml->preserveWhiteSpace = false;
     $root = $xml->createElement('root');
     $xml->appendChild($root);
     $depth = 0;
     $currentChildren = array();
     foreach ($nodes as $node) {
         $element = $xml->createElement('element');
         $element->setAttribute('id', $node['id']);
         $element->setAttribute('name', $node['name']);
         $element->setAttribute('lft', $node['lft']);
         $element->setAttribute('rgt', $node['rgt']);
         $children = $xml->createElement('children');
         $element->appendChild($children);
         if ($node['depth'] == 0) {
             // Handle root
             $root->appendChild($element);
             $currentChildren[0] = $children;
         } elseif ($node['depth'] > $depth) {
             // is a new sub level
             $currentChildren[$depth]->appendChild($element);
             $currentChildren[$node['depth']] = $children;
         } elseif ($node['depth'] == $depth || $node['depth'] < $depth) {
             // is at the same level
             $currentChildren[$node['depth'] - 1]->appendChild($element);
         }
         $depth = $node['depth'];
     }
     return $xml->saveXML();
 }
开发者ID:visualweber,项目名称:appzf1,代码行数:39,代码来源:Output.php

示例11: errorHandler

function errorHandler($errno, $errstr, $errfile, $errline, $errcontext)
{
    # capture some additional information
    $agent = $_SERVER['HTTP_USER_AGENT'];
    $ip = $_SERVER['REMOTE_ADDR'];
    $referrer = $_SERVER['HTTP_REFERER'];
    $dt = date("Y-m-d H:i:s (T)");
    # grab email info if available
    global $err_email, $err_user_name;
    # use this to email problem to maintainer if maintainer info is set
    if (isset($err_user_name) && isset($err_email)) {
    }
    # Write error message to user with less details
    $xmldoc = new DomDocument('1.0');
    $xmldoc->formatOutput = true;
    # Set root
    $root = $xmldoc->createElement("error_handler");
    $root = $xmldoc->appendChild($root);
    # Set child
    $occ = $xmldoc->createElement("error");
    $occ = $root->appendChild($occ);
    # Write error message
    $child = $xmldoc->createElement("error_message");
    $child = $occ->appendChild($child);
    $fvalue = $xmldoc->createTextNode("Your request has returned an error: " . $errstr);
    $fvalue = $child->appendChild($fvalue);
    $xml_string = $xmldoc->saveXML();
    echo $xml_string;
    # exit request
    exit;
}
开发者ID:oliviervanre,项目名称:GeolocOptinAdhoc,代码行数:31,代码来源:error.inc.php

示例12: createXml

 /**
  * @param $nameRoot - имя корня xml
  * @param $nameBigElement - имя узла в который записываются данные из массива $data
  * @param $data - массив с данными выгружеными из таблицы
  */
 function createXml($nameRoot, $nameBigElement, $data)
 {
     // создает XML-строку и XML-документ при помощи DOM
     $dom = new DomDocument($this->version, $this->encode);
     // добавление корня
     $root = $dom->appendChild($dom->createElement($nameRoot));
     // отбираем названия полей таблицы
     foreach (array_keys($data[0]) as $k) {
         if (is_string($k)) {
             $key[] = $k;
         }
     }
     // формируем элементы с данными
     foreach ($data as $d) {
         //добавление элемента $nameBigElement в корень
         $bigElement = $root->appendChild($dom->createElement($nameBigElement));
         foreach ($key as $k) {
             $element = $bigElement->appendChild($dom->createElement($k));
             $element->appendChild($dom->createTextNode($d[$k]));
         }
     }
     // сохраняем результат в файл
     $dom->save('format/' . $this->nameFile);
     unset($dom);
 }
开发者ID:AlexB2015,项目名称:dz32,代码行数:30,代码来源:XmlGenerate.class.php

示例13: prepareData

 protected function prepareData()
 {
     $v4b43b0aee35624cd95b910189b3dc231 = $this->reader;
     $v9a09b4dfda82e3e665e31092d1c3ec8d = new DomDocument();
     $v5118e2d6cb8d101c16049b9cf18de377 = $v9a09b4dfda82e3e665e31092d1c3ec8d->createElement("yml_catalog");
     $v9a09b4dfda82e3e665e31092d1c3ec8d->appendChild($v5118e2d6cb8d101c16049b9cf18de377);
     $v63a9f0ea7bb98050796b649e85481845 = $v9a09b4dfda82e3e665e31092d1c3ec8d->createElement("shop");
     $v5118e2d6cb8d101c16049b9cf18de377->appendChild($v63a9f0ea7bb98050796b649e85481845);
     $v7a86c157ee9713c34fbd7a1ee40f0c5a = $this->offset;
     while ($v4b43b0aee35624cd95b910189b3dc231->read() && $v4b43b0aee35624cd95b910189b3dc231->name != 'categories') {
         if ($v4b43b0aee35624cd95b910189b3dc231->nodeType != XMLReader::ELEMENT) {
             continue;
         }
         if ($v4b43b0aee35624cd95b910189b3dc231->name == 'yml_catalog' || $v4b43b0aee35624cd95b910189b3dc231->name == 'shop') {
             continue;
         }
         $v8e2dcfd7e7e24b1ca76c1193f645902b = $v4b43b0aee35624cd95b910189b3dc231->expand();
         $v63a9f0ea7bb98050796b649e85481845->appendChild($v8e2dcfd7e7e24b1ca76c1193f645902b);
     }
     $v4757fe07fd492a8be0ea6a760d683d6e = 0;
     while ($v4b43b0aee35624cd95b910189b3dc231->read() && $v4757fe07fd492a8be0ea6a760d683d6e < $v7a86c157ee9713c34fbd7a1ee40f0c5a) {
         if ($v4b43b0aee35624cd95b910189b3dc231->nodeType != XMLReader::ELEMENT) {
             continue;
         }
         if ($v4b43b0aee35624cd95b910189b3dc231->name == 'category' || $v4b43b0aee35624cd95b910189b3dc231->name == 'offer') {
             $v4757fe07fd492a8be0ea6a760d683d6e++;
         }
     }
     $this->offset += $v4757fe07fd492a8be0ea6a760d683d6e;
     $this->doc = $v9a09b4dfda82e3e665e31092d1c3ec8d;
 }
开发者ID:BGCX261,项目名称:zimmerli-svn-to-git,代码行数:31,代码来源:ymlSplitter.php

示例14: __construct

 /**
  * Constructor for AppKitXmlTag
  * @param string $tag_name
  * @param string $content
  */
 public function __construct($tag_name, $content = null)
 {
     $this->dom = new DOMDocument('1.0');
     $this->tag = $this->dom->createElement($tag_name);
     if ($content !== null) {
         $this->setContent($content);
     }
 }
开发者ID:philippjenni,项目名称:icinga-web,代码行数:13,代码来源:AppKitXmlTag.class.php

示例15: __construct

 /**
  * Constructor
  * @return unknown_type
  */
 public function __construct()
 {
     $this->_document = new DOMDocument();
     //create structute /xml/content
     $this->_document->appendChild($this->_document->createElement('xml'));
     $this->_contentNode = $this->_document->createElement('content');
     $this->_document->documentElement->appendChild($this->_contentNode);
 }
开发者ID:kandy,项目名称:system,代码行数:12,代码来源:PartialRenderer.php


注:本文中的DomDocument::createElement方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。