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


PHP object::appendChild方法代码示例

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


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

示例1: __construct

 /**
  * Constructor
  *
  * Attempts to load the correct layout xml file
  *
  * @param string $name
  * @return object
  */
 public function __construct($name = null)
 {
     if (pathinfo($name, PATHINFO_EXTENSION)) {
         $this->path = $name;
         $this->name = pathinfo($name, PATHINFO_FILENAME);
     } else {
         $this->path = $this->_zula->getDir('config') . '/layouts/' . $name . '.xml';
         $this->name = $name;
     }
     if (Registry::has('sql')) {
         // Find the regex for this layout
         $pdoSt = $this->_sql->prepare('SELECT regex FROM {PREFIX}layouts WHERE name = ?');
         $pdoSt->execute(array($name));
         if ($regex = $pdoSt->fetchColumn()) {
             $this->regex = $regex;
         }
         $pdoSt->closeCursor();
     }
     // Load the DomDocument (or create if needed)
     $this->dom = new DomDocument('1.0', 'UTF-8');
     $this->dom->preserveWhiteSpace = false;
     $this->dom->formatOutput = true;
     if (is_file($this->path)) {
         $this->dom->load($this->path);
     } else {
         $this->dom->appendChild($this->dom->createElement('controllers'));
     }
 }
开发者ID:jinshana,项目名称:tangocms,代码行数:36,代码来源:Layout.php

示例2: appendChildren

 /**
  * Convert object to XML.
  * 
  * @param object $doc DOMDocument
  * @param object $parent DOMElement
  * @param string $nodeName name of the node you want to convert to
  * @param array $arrayToConvert array (or 2d array) you are trying to convert
  *
  * Adds one or more properly formatted xml nodes to the parent
  */
 public function appendChildren($doc, $parent, $nodeName, $arrayToConvert)
 {
     if (array_key_exists($nodeName, $arrayToConvert)) {
         //one object was sent.
         $elem = $doc->createElement($nodeName, $arrayToConvert[$nodeName]);
         $parent->appendChild($elem);
         foreach ($arrayToConvert as $key => $val) {
             if ($key != $nodeName) {
                 $attrName = $doc->createAttribute($key);
                 $elem->appendChild($attrName);
                 $attrVal = $doc->createTextNode($val);
                 $attrName->appendChild($attrVal);
             }
         }
     } else {
         //array of objects was sent
         foreach ($arrayToConvert as $key => $val) {
             $elem = $doc->createElement($nodeName, $val[$nodeName]);
             $parent->appendChild($elem);
             foreach ($val as $attrName => $attrVal) {
                 if ($attrName != $nodeName) {
                     $attribute = $doc->createAttribute($attrName);
                     $elem->appendChild($attribute);
                     $attributevalue = $doc->createTextNode($attrVal);
                     $attribute->appendChild($attributevalue);
                 }
             }
         }
     }
 }
开发者ID:electromute,项目名称:gnip-php,代码行数:40,代码来源:GnipDOMDocument.php

示例3: __construct

 /**
  * create new model
  *
  * @param    array
  * @param    object
  */
 public function __construct($node, $session = null)
 {
     $this->dom = new DOMDocument();
     $ebay = new DOMElement('eBay');
     $ebay = $this->dom->appendChild($ebay);
     $pf = new DOMElement('ProductFinders');
     $pf = $ebay->appendChild($pf);
     $newNode = $this->dom->importNode($node, true);
     $pf->appendChild($newNode);
 }
开发者ID:rtconner,项目名称:services_ebay,代码行数:16,代码来源:ProductFinder.php

示例4: toXML

 /**
  * Converts the place to properly formatted XML.
  * 
  * @param object $doc DOMDocument object
  * @param object $root DOMDocument root
  */
 public function toXML($doc, $root)
 {
     $place = $doc->createElement('place');
     if ($this->point != null) {
         $place->appendChild($doc->createElement('point', $this->point));
     }
     if ($this->elev != null) {
         $place->appendChild($doc->createElement('elev', $this->elev));
     }
     if ($this->floor != null) {
         $place->appendChild($doc->createElement('floor', $this->floor));
     }
     if ($this->featuretypetag != null) {
         $place->appendChild($doc->createElement('featuretypetag', $this->featuretypetag));
     }
     if ($this->featurename != null) {
         $place->appendChild($doc->createElement('featurename', $this->featurename));
     }
     if ($this->relationshiptag != null) {
         $place->appendChild($doc->createElement('relationshiptag', $this->relationshiptag));
     }
     if ($place->hasChildNodes()) {
         $root->appendChild($place);
     }
 }
开发者ID:electromute,项目名称:gnip-php,代码行数:31,代码来源:Place.php

示例5: addItem

 /**
  * Adding the Items to the RSS Feed.
  *
  * @access public
  * @param array $aItems
  * @return object this
  */
 public function addItem($aItems)
 {
     // Create an item
     $oItem = $this->createElement('item');
     foreach ($aItems as $sElement => $sValue) {
         switch ($sElement) {
             // Create the sub elements here
             case 'image':
             case 'skipHour':
             case 'skipDay':
                 $oIm = $this->createElement('image');
                 $this->_oChannel->appendChild($oIm);
                 foreach ($aValue as $sSubElement => $sSubValue) {
                     $oSub = $this->createElement($sSubElement, $sSubValue);
                     $oIm->appendChild($oSub);
                 }
                 break;
             case 'title':
             case 'pubDate':
             case 'link':
             case 'description':
             case 'copyright':
             case 'managingEditor':
             case 'webMaster':
             case 'lastbuildDate':
             case 'category':
             case 'generator':
             case 'docs':
             case 'language':
             case 'cloud':
             case 'ttl':
             case 'rating':
             case 'textInput':
             case 'source':
                 $oItem->appendChild($this->createElement($sElement, $sValue));
                 break;
         }
     }
     // Append the item to the channel
     $this->_oChannel->appendChild($oItem);
     // Allow chaining with $this
     return $this;
 }
开发者ID:joswilson,项目名称:NotJustOK,代码行数:50,代码来源:Rss.class.php

示例6: xmlAddAttribute

 /**
  * 
  * @param object $node
  * @param string $name
  * @param string $value Default is NULL
  * @return object
  */
 function xmlAddAttribute($node, $name, $value = NULL)
 {
     $dom = $node->ownerDocument;
     $attribute = $dom->createAttribute($name);
     $node->appendChild($attribute);
     if ($value != NULL) {
         $attribute_value = $dom->createTextNode($value);
         $attribute->appendChild($attribute_value);
     }
     return $node;
 }
开发者ID:khalid9th,项目名称:ocAds,代码行数:18,代码来源:hXML.php

示例7: toXML

 /**
  * Converts the place to properly formatted XML..
  * 
  * @param object $doc DOMDocument object
  * @param object $root DOMDocument root
  */
 public function toXML($doc, $root)
 {
     $payload = $doc->createElement('payload');
     if ($this->title != null) {
         $payload->appendChild($doc->createElement('title', $this->title));
     }
     if ($this->body != null) {
         $payload->appendChild($doc->createElement('body', $this->body));
     }
     if ($this->mediaURL != null) {
         $doc->appendChildren($doc, $payload, "mediaURL", $this->mediaURL);
     }
     $payload->appendChild($doc->createElement('raw', $this->raw));
     if ($payload->hasChildNodes()) {
         $root->appendChild($payload);
     }
 }
开发者ID:electromute,项目名称:gnip-php,代码行数:23,代码来源:Payload.php

示例8: do_item

 /**
  * Append a single snippet item to the document
  * @param array $snippet
  */
 protected function do_item($snippet)
 {
     $item = $this->dom->createElement('snippet');
     $item = $this->root->appendChild($item);
     foreach ($snippet as $field_name => $field_value) {
         /*  Don't export certain fields */
         if (in_array($field_name, $this->exclude_fields)) {
             continue;
         }
         /* Create a new element for each field */
         $field = $this->dom->createElement($field_name);
         $field = $item->appendChild($field);
         /* Add the field's content */
         $value = $this->dom->createTextNode($field_value);
         $value = $field->appendChild($value);
     }
 }
开发者ID:kgoedecke,项目名称:kevingoedecke-blog,代码行数:21,代码来源:class-export.php

示例9: __set_value

 /**
  * Setter for the node's value. Automatically uses CDATA when needed
  *
  * @access	protected
  * @param	mixed		Value
  * @return	void
  */
 protected function __set_value($value)
 {
     foreach ($this->element->childNodes as $child) {
         $this->element->removeChild($child);
     }
     // It could be that the passed value is an array
     if (is_array($value)) {
         foreach ($value as $node_name => $node_value) {
             $this->add_node($node_name, $node_value);
         }
         return;
     }
     // Figure out whether to use CDATA or not
     if (strpos($value, '<') !== false || strpos($value, '>') !== false || strpos($value, '&') !== false) {
         $text_node = $this->document->createCDATASection($value);
     } else {
         $text_node = $this->document->createTextNode($value);
     }
     $this->element->appendChild($text_node);
 }
开发者ID:phpbb,项目名称:mpv,代码行数:27,代码来源:cortex_xml.php

示例10: _fromArray

 /**
  * Recursive method to create childs from array
  *
  * @param object $dom Handler to DOMDocument
  * @param object $node Handler to DOMElement (child)
  * @param array $data Array of data to append to the $node.
  * @param string $format Either 'attribute' or 'tags'.  This determines where nested keys go.
  * @return void
  */
 protected static function _fromArray($dom, $node, &$data, $format)
 {
     if (empty($data) || !is_array($data)) {
         return;
     }
     foreach ($data as $key => $value) {
         if (is_string($key)) {
             if (!is_array($value)) {
                 if (is_bool($value)) {
                     $value = (int) $value;
                 } elseif ($value === null) {
                     $value = '';
                 }
                 $isNamespace = strpos($key, 'xmlns:');
                 $nsUri = null;
                 if ($isNamespace !== false) {
                     $node->setAttributeNS('http://www.w3.org/2000/xmlns/', $key, $value);
                     continue;
                 }
                 if ($key[0] !== '@' && $format === 'tags') {
                     $child = $dom->createElement($key, $value);
                     $node->appendChild($child);
                 } else {
                     if ($key[0] === '@') {
                         $key = substr($key, 1);
                     }
                     $attribute = $dom->createAttribute($key);
                     $attribute->appendChild($dom->createTextNode($value));
                     $node->appendChild($attribute);
                 }
             } else {
                 if ($key[0] === '@') {
                     throw new XmlException(__('Invalid array'));
                 }
                 if (array_keys($value) === range(0, count($value) - 1)) {
                     // List
                     foreach ($value as $item) {
                         $data = compact('dom', 'node', 'key', 'format');
                         $data['value'] = $item;
                         self::__createChild($data);
                     }
                 } else {
                     // Struct
                     self::__createChild(compact('dom', 'node', 'key', 'value', 'format'));
                 }
             }
         } else {
             throw new XmlException(__('Invalid array'));
         }
     }
 }
开发者ID:robotarmy,项目名称:Phog,代码行数:60,代码来源:xml.php

示例11: createWSDL_service

 /**
  * Create the service node
  *
  * @return void
  */
 protected function createWSDL_service()
 {
     /*
     	    <service name="myService">
     	        <port name="myServicePort" binding="typens:myServiceBinding">
     	            <soap:address location="http://dschini.org/test1.php"/>
     	        </port>
     	    </service>
     */
     $service = $this->wsdl->createElement('service');
     $service->setAttribute('name', $this->classname);
     $port = $this->wsdl->createElement('port');
     $port->setAttribute('name', $this->classname . 'Port');
     $port->setAttribute('binding', 'typens:' . $this->classname . 'Binding');
     $adress = $this->wsdl->createElement('soap:address');
     $adress->setAttribute('location', $this->protocol . '://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF']);
     $port->appendChild($adress);
     $service->appendChild($port);
     $this->wsdl_definitions->appendChild($service);
 }
开发者ID:quangbt2005,项目名称:vhost-kis,代码行数:25,代码来源:Webservice.php

示例12: getOutput

 /**
  * Retreives the output of this object.
  *
  * @return void
  *
  * @author     Benoit Grégoire <benoitg@coeus.ca>
  * @author     Francois Proulx <francois.proulx@gmail.com>
  * @author     Max Horváth <max.horvath@freenet.de>
  * @copyright  2004-2006 Benoit Grégoire, Technologies Coeus inc.
  * @copyright  2004-2006 Francois Proulx, Technologies Coeus inc.
  * @copyright  2006 Max Horváth, Horvath Web Consulting
  */
 public function getOutput()
 {
     $db = AbstractDb::getObject();
     // Root node
     $_rss = $this->_xmldoc->createElement("rss");
     $this->_xmldoc->appendChild($_rss);
     $_rss->setAttribute('version', '2.0');
     // channel
     $_channel = $this->_xmldoc->createElement("channel");
     $_rss->appendChild($_channel);
     /*
      * Required channel elements
      */
     // title
     $_title = $this->_xmldoc->createElement("title");
     $_title = $_channel->appendChild($_title);
     $_textNode = $this->_xmldoc->createTextNode($this->_network->getName() . ": " . _("Newest Hotspots"));
     $_title->appendChild($_textNode);
     // link
     $_link = $this->_xmldoc->createElement("link");
     $_channel->appendChild($_link);
     $_textNode = $this->_xmldoc->createTextNode($this->_network->getWebSiteURL());
     $_link->appendChild($_textNode);
     // description
     $_description = $this->_xmldoc->createElement("description");
     $_channel->appendChild($_description);
     $_textNode = $this->_xmldoc->createTextNode(_("List of the most recent Hotspots opened by the network: ") . $this->_network->getName());
     $_description->appendChild($_textNode);
     /*
      * Optional channel elements
      */
     // language
     $_language = $this->_xmldoc->createElement("language");
     $_channel->appendChild($_language);
     if (User::getCurrentUser() != null) {
         $_textNode = $this->_xmldoc->createTextNode(substr(User::getCurrentUser()->getPreferedLocale(), 0, 5));
     } else {
         $_textNode = $this->_xmldoc->createTextNode("en-US");
     }
     $_language->appendChild($_textNode);
     // copyright
     $_copyright = $this->_xmldoc->createElement("copyright");
     $_channel->appendChild($_copyright);
     $_textNode = $this->_xmldoc->createTextNode(_("Copyright ") . $this->_network->getName());
     $_copyright->appendChild($_textNode);
     // webMaster
     if ($this->_network->getTechSupportEmail() != "") {
         $_webMaster = $this->_xmldoc->createElement("webMaster");
         $_channel->appendChild($_webMaster);
         $_textNode = $this->_xmldoc->createTextNode($this->_network->getTechSupportEmail());
         $_webMaster->appendChild($_textNode);
     }
     // pubDate
     $_pubDate = $this->_xmldoc->createElement("pubDate");
     $_channel->appendChild($_pubDate);
     $_textNode = $this->_xmldoc->createTextNode(gmdate("D, d M Y H:i:s \\G\\M\\T", time()));
     $_pubDate->appendChild($_textNode);
     /**
      * lastBuildDate
      *
      * <lastBuildDate> -- The date-time the last time the content of the
      * channel changed.
      *
      * Make a request through the database for the latest modification date
      * of an object.
      *
      * @todo The latest modification date of an object should be an
      *       object property
      */
     $db->execSqlUniqueRes("SELECT EXTRACT(epoch FROM MAX(creation_date)) as date_last_hotspot_opened FROM nodes WHERE network_id = '" . $db->escapeString($this->_network->getId()) . "' AND (node_deployment_status = 'DEPLOYED' OR node_deployment_status = 'NON_WIFIDOG_NODE')", $_lastHotspotRow, false);
     $_lastBuildDate = $this->_xmldoc->createElement("lastBuildDate");
     $_channel->appendChild($_lastBuildDate);
     $_textNode = $this->_xmldoc->createTextNode(gmdate("D, d M Y H:i:s \\G\\M\\T", $_lastHotspotRow['date_last_hotspot_opened']));
     $_lastBuildDate->appendChild($_textNode);
     // generator
     $_generator = $this->_xmldoc->createElement("generator");
     $_channel->appendChild($_generator);
     $_textNode = $this->_xmldoc->createTextNode(WIFIDOG_NAME . " " . WIFIDOG_VERSION);
     $_generator->appendChild($_textNode);
     // docs
     $_docs = $this->_xmldoc->createElement("docs");
     $_channel->appendChild($_docs);
     $_textNode = $this->_xmldoc->createTextNode("http://blogs.law.harvard.edu/tech/rss");
     $_docs->appendChild($_textNode);
     // image
     /*if (defined('NETWORK_LOGO_NAME') && file_exists(WIFIDOG_ABS_FILE_PATH . "local_content/common/" . constant('NETWORK_LOGO_NAME'))) {
                 $_image = $this->_xmldoc->createElement("image");
                 $_channel->appendChild($_image);
//.........这里部分代码省略.........
开发者ID:cnlangzi,项目名称:wifidog-auth,代码行数:101,代码来源:NodeListRSS.php

示例13: _mergeNodes

 /**
  * Merges nodes of newly added menu xml file
  *
  * @param object $oDomElemTo   merge target
  * @param object $oDomElemFrom merge source
  * @param object $oXPathTo     node path
  * @param object $oDomDocTo    node to append child
  * @param string $sQueryStart  node query
  */
 protected function _mergeNodes($oDomElemTo, $oDomElemFrom, $oXPathTo, $oDomDocTo, $sQueryStart)
 {
     foreach ($oDomElemFrom->childNodes as $oFromNode) {
         if ($oFromNode->nodeType === XML_ELEMENT_NODE) {
             $sFromAttrName = $oFromNode->getAttribute('id');
             $sFromNodeName = $oFromNode->tagName;
             // find current item
             $sQuery = "{$sQueryStart}/{$sFromNodeName}[@id='{$sFromAttrName}']";
             $oCurNode = $oXPathTo->query($sQuery);
             // if not found - append
             if ($oCurNode->length == 0) {
                 $oDomElemTo->appendChild($oDomDocTo->importNode($oFromNode, true));
             } else {
                 $oCurNode = $oCurNode->item(0);
                 // if found copy all attributes and check childnodes
                 $this->_copyAttributes($oCurNode, $oFromNode);
                 if ($oFromNode->childNodes->length) {
                     $this->_mergeNodes($oCurNode, $oFromNode, $oXPathTo, $oDomDocTo, $sQuery);
                 }
             }
         }
     }
 }
开发者ID:ioanok,项目名称:symfoxid,代码行数:32,代码来源:oxnavigationtree.php

示例14: getOutput

 /**
  * Displays the output of this object.
  *
  * @return void
  *
  * @author     Benoit Gregoire <benoitg@coeus.ca>
  * @author     Francois Proulx <francois.proulx@gmail.com>
  * @author     Max Horváth <max.horvath@freenet.de>
  * @author     Joe Bowser <bowserj@resist.ca>
  * @copyright  2004-2006 Benoit Gregoire, Technologies Coeus inc.
  * @copyright  2004-2006 Francois Proulx, Technologies Coeus inc.
  * @copyright  2006 Max Horváth, Horvath Web Consulting
  * @copyright  2006 Joe Bowser
  */
 public function getOutput()
 {
     $_kml = $this->_xmldoc->createElement("kml");
     $_kml->setAttribute('xmlns', 'http://earth.google.com/kml/2.0');
     $this->_xmldoc->appendChild($_kml);
     // Document
     $_document = $this->_xmldoc->createElement("Document");
     $_kml->appendChild($_document);
     /*
      * Style Elements (Up Nodes)
      */
     $_style_up = $this->_xmldoc->createElement("Style");
     $_style_up->setAttribute('id', 'node_up');
     $_document->appendChild($_style_up);
     $_iconStyle = $this->_xmldoc->createElement("IconStyle");
     $_style_up->appendChild($_iconStyle);
     /* Since scale is the same, we only have to define it once */
     $_scale = $this->_xmldoc->createElement("scale");
     $_iconStyle->appendChild($_scale);
     $_textNode = $this->_xmldoc->createTextNode("0.5");
     $_scale->appendChild($_textNode);
     $_icon = $this->_xmldoc->createElement("Icon");
     $_iconStyle->appendChild($_icon);
     $_href = $this->_xmldoc->createElement("href");
     $_icon->appendChild($_href);
     $_textNode = $this->_xmldoc->createTextNode(BASE_URL_PATH . "images/HotspotStatusMap/up.png");
     $_href->appendChild($_textNode);
     /*
      * Style Elements (Down Nodes)
      */
     $_style_down = $this->_xmldoc->createElement("Style");
     $_style_down->setAttribute('id', 'node_down');
     $_document->appendChild($_style_down);
     $_iconStyle = $this->_xmldoc->createElement("IconStyle");
     $_style_down->appendChild($_iconStyle);
     $_scale = $this->_xmldoc->createElement("scale");
     $_iconStyle->appendChild($_scale);
     $_textNode = $this->_xmldoc->createTextNode("0.5");
     $_scale->appendChild($_textNode);
     $_iconStyle->appendChild($_scale);
     $_icon = $this->_xmldoc->createElement("Icon");
     $_iconStyle->appendChild($_icon);
     $_href = $this->_xmldoc->createElement("href");
     $_icon->appendChild($_href);
     $_textNode = $this->_xmldoc->createTextNode(BASE_URL_PATH . "images/HotspotStatusMap/down.png");
     $_href->appendChild($_textNode);
     /*
      * Style Elements (Unknown Nodes)
      */
     $_style_unknown = $this->_xmldoc->createElement("Style");
     $_style_unknown->setAttribute('id', 'node_unknown');
     $_document->appendChild($_style_unknown);
     $_iconStyle = $this->_xmldoc->createElement("IconStyle");
     $_style_unknown->appendChild($_iconStyle);
     $_scale = $this->_xmldoc->createElement("scale");
     $_iconStyle->appendChild($_scale);
     $_textNode = $this->_xmldoc->createTextNode("0.5");
     $_scale->appendChild($_textNode);
     $_icon = $this->_xmldoc->createElement("Icon");
     $_iconStyle->appendChild($_icon);
     $_href = $this->_xmldoc->createElement("href");
     $_icon->appendChild($_href);
     $_textNode = $this->_xmldoc->createTextNode(BASE_URL_PATH . "images/HotspotStatusMap/unknown.png");
     $_href->appendChild($_textNode);
     /*
      * Creating the Folder
      */
     $_folder = $this->_xmldoc->createElement("Folder");
     $_document->appendChild($_folder);
     $_name = $this->_xmldoc->createElement("name");
     $_folder->appendChild($_name);
     $_textNode = $this->_xmldoc->createTextNode($this->_network->getName());
     $_name->appendChild($_textNode);
     /*
      * Creating the Placemarks (Nodes)
      */
     if ($this->_nodes) {
         foreach ($this->_nodes as $_nodeData) {
             $_node = Node::getObject($_nodeData['node_id']);
             $this->_network = $_node->getNetwork();
             $_placemark = $this->_xmldoc->createElement("Placemark");
             $_folder->appendChild($_placemark);
             // Hotspot name
             $_hotspotName = $this->_xmldoc->createElement("name", htmlspecialchars($_node->getName(), ENT_QUOTES));
             $_placemark->appendChild($_hotspotName);
             $_html_data = "<b>" . _("Address") . ":</b><br />" . $_node->getCivicNumber() . " " . $_node->getStreetName() . "<br />" . $_node->getCity() . "," . $_node->getProvince() . "<br />" . $_node->getCountry() . "<br />" . $_node->getPostalCode() . "<br /><br /> <b>" . _("URL") . ":</b> <a href='" . $_node->getWebSiteURL() . "'>" . $_node->getWebSiteURL() . "</a> <br /> <b> " . _("Email") . ":</b> <a href='mailto:" . $_node->getEmail() . "'>" . $_node->getEmail() . "</a>";
//.........这里部分代码省略.........
开发者ID:cnlangzi,项目名称:wifidog-auth,代码行数:101,代码来源:NodeListKML.php

示例15: attachRelations

 /**
  * Builds and attaches relations to an item-level element (item or search)
  *
  * @param  object $element DOMElement for the item or search
  * @param  array  $relations associative array of relations to attach
  */
 protected function attachRelations(&$element, &$relations)
 {
     // create the relations element
     $relations_element = $this->dom->createElement('relations');
     $element->appendChild($relations_element);
     foreach ($relations as $relation) {
         // create the relation element
         $relation_element = $this->dom->createElement('relation');
         $relations_element->appendChild($relation_element);
         // if the id isn't set (creating a new relation)
         // and the action isn't set
         // then set the action to create
         if (empty($relation['id']) && empty($relation['action'])) {
             $relation['action'] = Services_WorkXpress::RELATION_ACTION_CREATE;
         }
         // set the action
         $relation_element->setAttribute('action', $relation['action']);
         // set the relation type id
         $relation_element->setAttribute('relation_type_id', $relation['relation_type_id']);
         // set the reference
         if (!empty($relation['reference'])) {
             $relation_element->setAttribute('reference', $relation['reference']);
         }
         // set proper attributes depending on if we're creating, recycling,
         // or deleting the relationship
         switch ($relation['action']) {
             case Services_WorkXpress::RELATION_ACTION_CREATE:
                 // set the item type id
                 if (!empty($relation['item_type_id'])) {
                     $relation_element->setAttribute('item_type_id', $relation['item_type_id']);
                 }
                 // set the related item side
                 if (!empty($relation['related_item_side'])) {
                     $relation_element->setAttribute('related_item_side', $relation['related_item_side']);
                 }
                 // set the related item type id
                 if (!empty($relation['related_item_type_id'])) {
                     $relation_element->setAttribute('related_item_type_id', $relation['related_item_type_id']);
                 }
                 // set the related item id
                 if (!empty($relation['related_item_id'])) {
                     $relation_element->setAttribute('related_item_id', $relation['related_item_id']);
                 }
                 break;
             case Services_WorkXpress::RELATION_ACTION_DELETE:
             case Services_WorkXpress::RELATION_ACTION_RECYCLE:
                 // set the id
                 if (!empty($relation['id'])) {
                     $relation_element->setAttribute('id', $relation['id']);
                 }
                 break;
         }
         // end switch $relation['action']
     }
     // end foreach - loop through the relations
     return true;
 }
开发者ID:jamesiarmes,项目名称:php-ups-api,代码行数:63,代码来源:StoreItemData.php


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