本文整理汇总了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);
}