當前位置: 首頁>>代碼示例>>PHP>>正文


PHP SimpleXMLElement::finalize方法代碼示例

本文整理匯總了PHP中SimpleXMLElement::finalize方法的典型用法代碼示例。如果您正苦於以下問題:PHP SimpleXMLElement::finalize方法的具體用法?PHP SimpleXMLElement::finalize怎麽用?PHP SimpleXMLElement::finalize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在SimpleXMLElement的用法示例。


在下文中一共展示了SimpleXMLElement::finalize方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: putpost

 private function putpost($method)
 {
     if ($this->_res === null) {
         return false;
     }
     $data = $this->getData();
     if ($method === RestMethodEnum::RM_POST) {
         try {
             $xml = new SimpleXMLElement($data);
         } catch (Exception $e) {
             $this->setError(RestErrorEnum::RE_INVALID_REPRESENTATION);
             return false;
         }
         $xp = $xml->xpath("publication:publication");
         if (count($xp) > 0) {
             $id = strval($xp[0]->attributes()->id);
         }
         if ($id == '') {
             $this->setError(RestErrorEnum::RE_INVALID_REPRESENTATION);
             return false;
         }
         try {
             $xml = new DOMDocument();
             $xml->loadXML(strval(RestAPIHelper::wrapResponse(strval($this->get()))));
             $xpath = new DOMXPath($xml);
             $xpres = $xpath->query('//publication:publication[@id="' . $id . '"]');
         } catch (Exception $e) {
             $this->setError(RestErrorEnum::RE_INVALID_REPRESENTATION);
             return false;
         }
         if ($xpres !== false) {
             $xnode = $xpres->item(0);
             $xparent = $xnode->parentNode;
             $xparent->removeChild($xpres->item(0));
             try {
                 $xml = new SimpleXMLElement($xml->saveXML());
             } catch (Exception $e) {
                 $this->setError(RestErrorEnum::RE_INVALID_REPRESENTATION);
                 return false;
             }
         } else {
             $this->setError(RestErrorEnum::RE_ITEM_NOT_FOUND);
             return false;
         }
     } else {
         try {
             $xml = new SimpleXMLElement(strval(RestAPIHelper::wrapResponse($this->get())));
         } catch (Exception $e) {
             $this->setError(RestErrorEnum::RE_INVALID_REPRESENTATION);
             return false;
         }
     }
     try {
         $data = new SimpleXMLElement($data);
         $data = $data->xpath("//publication:publication");
     } catch (Exception $e) {
         $this->setError(RestErrorEnum::RE_INVALID_REPRESENTATION);
         return false;
     }
     if (count($data) > 0) {
         $data = $data[0]->asXML();
     } else {
         $this->setError(RestErrorEnum::RE_INVALID_REPRESENTATION);
         return false;
     }
     $data = array($data);
     $xp = $xml->xpath("publication:publication");
     foreach ($xp as $x) {
         $data[] = $x->asXML();
     }
     $data = '<application:application id="' . $this->_res->id . '">' . implode($data) . '</application:application>';
     $data = strval(RestAPIHelper::wrapResponse($data));
     $this->_pars['data'] = $data;
     $res = new RestAppList($this->_pars);
     $ret = $res->post();
     $ret = new SimpleXMLElement(strval($ret->finalize()));
     if ($method === RestMethodEnum::RM_POST) {
         $xp = $ret->xpath('//publication:publication[@id="' . $id . '"]');
     } else {
         // try to find the publication with the max id attribute, which should be the newest
         $xp = $ret->xpath('//publication:publication[not(@id <= preceding-sibling::publication:publication/@id) and not(@id <= following-sibling::publication:publication/@id)]');
         // if this fails, try to find the last publication, which still should be the newest,
         // since results are returned in DB (natural) order
         if (count($xp) == 0 || !is_array($xp)) {
             $xp = $ret->xpath('//publication:publication[last()]');
         }
     }
     $ret = array();
     foreach ($xp as $x) {
         $ret[] = $x->asXML();
     }
     return new XMLFragmentRestResponse($ret);
 }
開發者ID:IASA-GR,項目名稱:appdb-core,代碼行數:93,代碼來源:restapi_app.php


注:本文中的SimpleXMLElement::finalize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。