本文整理匯總了PHP中DomDocument::saveXML方法的典型用法代碼示例。如果您正苦於以下問題:PHP DomDocument::saveXML方法的具體用法?PHP DomDocument::saveXML怎麽用?PHP DomDocument::saveXML使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類DomDocument
的用法示例。
在下文中一共展示了DomDocument::saveXML方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: toString
/**
* Convert the internal dom instance to a string.
*
* @param boolean $format Whether to pretty format the string or not
*
* @return string
*/
public function toString($format = null)
{
if ($format) {
$this->dom->formatOutput = true;
}
return $this->dom->saveXML();
}
示例2: get
/**
* Return the HTML represented by the DOM
* @return string The requested HTML
*/
public function get()
{
$body_content = $this->query('//body/*');
$output = '';
foreach ($body_content as $node) {
$output .= $this->dom->saveXML($node->node);
}
return $output;
}
示例3: write
/**
* @see Drest\Writer\Writer::write()
*/
public function write(ResultSet $data)
{
$this->xml = new \DomDocument('1.0', 'UTF-8');
$this->xml->formatOutput = true;
$dataArray = $data->toArray();
if (key($dataArray) === 0) {
// If there is no key, we need to use a default
$this->xml->appendChild($this->convertArrayToXml('result', $dataArray));
} else {
$this->xml->appendChild($this->convertArrayToXml(key($dataArray), $dataArray[key($dataArray)]));
}
$this->data = $this->xml->saveXML();
}
示例4: flush
/** flush printer buffer */
public function flush()
{
$document = new \DomDocument('1.0', 'ISO-8859-15');
$checkstyle = new \DOMElement('checkstyle');
$document->appendChild($checkstyle);
$checkstyle->appendChild(new \DOMAttr('version', '6.5'));
// Write each file to the DOM
foreach ($this->files as $file_name => $error_list) {
$file = new \DOMElement('file');
$checkstyle->appendChild($file);
$file->appendChild(new \DOMAttr('name', $file_name));
// Write each error to the file
foreach ($error_list as $error_map) {
$error = new \DOMElement('error');
$file->appendChild($error);
// Write each element of the error as an attribute
// of the error
foreach ($error_map as $key => $value) {
$error->appendChild(new \DOMAttr($key, (string) $value));
}
}
}
$this->output->write($document->saveXML());
$this->files = [];
}
示例5: showAction
public function showAction()
{
set_time_limit(600);
// 10 min
// ini_set('output_buffering', '4096');
$nodeid = $this->getRequest()->getParam('id', -1);
$this->_zip = new Uman_ZipStream("pack_{$nodeid}.pkg");
$xml = new DomDocument('1.0', 'utf-8');
$root = $xml->appendChild(new DOMElement('package'));
$content = $xml->createElement('content');
$content = $root->appendChild($content);
$this->addLevel($this->_db->fetchAll($this->_rootsql, $nodeid), $content, $this->getRequest()->getParam('contentinc', false));
$packid = $this->_db->nextSequenceId('GEN_UID');
$this->addInfo($nodeid, $root, $packid);
$this->addTypes($root);
$this->_zip->add_file('info.xml', $xml->saveXML());
$this->_zip->finish();
$AdminDbModel = new Admin_Model_Admin();
$AdminDbModel->exportPackage($nodeid, $packid);
/* header("Content-type: application/x-zip");
header("Content-Disposition: attachment; filename=test.zip");
$zip = new ZipArchive();
if ($zip->open('php://output', ZIPARCHIVE::CREATE)!==TRUE) { // Пока не работает запись в поток
echo "cannot open \n";
exit;
}
$zip->addFromString('test.txt', '11111111111');
$zip->close();
*/
exit;
}
示例6: manipulate
/**
* General manipulate wrapper method.
*
* @param string $input An XML snippet to be manipulated. We are only interested
* in <abstract> snippets.
*
* @return string
* Manipulated string
*/
public function manipulate($input)
{
$dom = new \DomDocument();
$dom->loadxml($input, LIBXML_NSCLEAN);
$abstracts = $dom->getElementsByTagName('abstract');
if ($abstracts->length == 1) {
$abstract = $abstracts->item(0);
// Use Guzzle to hit the API.
$client = new Client();
try {
$original_text = urlencode($abstract->nodeValue);
$query = "?text={$original_text}&format=json";
$response = $client->get($this->arrpiUrl . $query);
// If there is a Guzzle error, log it and return the original snippet.
} catch (Exception $e) {
$this->log->addWarning("PiratizeAbstract", array('HTTP request error' => $e->getMessage()));
return $input;
}
$body = $response->getBody();
$translation = json_decode($body, true);
$abstract->nodeValue = urldecode($translation['translation']['pirate']);
// Log any instances where the translation differs from the original text.
if (urldecode($original_text) != $abstract->nodeValue) {
$this->log->addInfo("PiratizeAbstract", array('Record key' => $this->record_key, 'Source abstract text' => urldecode($original_text), 'Piratized abstract text' => $abstract->nodeValue));
}
// We're done, so return the modified snippet.
return $dom->saveXML($dom->documentElement);
} else {
return $input;
}
}
示例7: __toString
/**
* return the document as string.
*
* @access public
* @return string
*/
public function __toString()
{
$this->document->formatOutput = true;
$this->document->preserveWhitespace = false;
$title = $this->document->createElement('title', $this->getFullTitle());
$this->head->appendChild($title);
if (!empty($this->favicon)) {
$favicon = $this->document->createElement('link');
$favicon->setAttribute('rel', 'shortcut icon');
$favicon->setAttribute('href', $this->favicon);
$this->head->appendChild($favicon);
$favicon = $this->document->createElement('link');
$favicon->setAttribute('rel', 'icon');
$favicon->setAttribute('href', $this->favicon);
$this->head->appendChild($favicon);
}
if (!empty($this->keywords)) {
$keywords = $this->document->createElement('meta');
$keywords->setAttribute('name', 'keywords');
$keywords->setAttribute('content', $this->keywords);
$this->head->appendChild($keywords);
}
$html = $this->document->getElementsByTagName('html')->item(0);
$html->appendChild($this->head);
$html->appendChild($this->body);
return $this->document->saveXML();
}
示例8: makeXml
function makeXml($dbObject)
{
header("Content-Type: application/xml");
$doc = new DomDocument('1.0', 'UTF-8');
$uid = $doc->createElement('uid');
for ($i = 0; $i < $dbObject->rowCount(); $i++) {
$result = $dbObject->fetch();
if ($i === 0) {
$id = $doc->createAttribute('id');
$id->value = $result['usernum'];
$uid->appendChild($id);
$doc->appendChild($uid);
}
$prefix = array($result['num'], $result['in_out'], $result['type'], $result['amount'], $result['time'], $result['detail']);
list($tnum, $inout, $type, $amount, $time, $detail) = $prefix;
$trade_num = $doc->createElement('tnum');
$tr_att = $doc->createAttribute('nu');
$tr_att->value = $tnum;
$trade_num->appendChild($tr_att);
$trade_num->appendChild($doc->createElement('inout', $inout));
$trade_num->appendChild($doc->createElement('type', $type));
$trade_num->appendChild($doc->createElement('amount', $amount));
$trade_num->appendChild($doc->createElement('time', $time));
$trade_num->appendChild($doc->createElement('detail', $detail));
$uid->appendChild($trade_num);
}
$xml = $doc->saveXML();
print $xml;
}
示例9: do_refresh_task
function do_refresh_task($task_id_)
{
$task = Abstract_Task::load($task_id_);
if (!is_object($task)) {
Logger::error('main', '(ajax/installable_applications) Task ' . $task_id_ . ' not found');
header('Content-Type: text/xml; charset=utf-8');
$dom = new DomDocument('1.0', 'utf-8');
$node = $dom->createElement('usage');
$node->setAttribute('status', 'task not found');
$dom->appendChild($node);
die($dom->saveXML());
}
$task->refresh();
if (!$task->succeed()) {
header('Content-Type: text/xml; charset=utf-8');
$dom = new DomDocument('1.0', 'utf-8');
$node = $dom->createElement('task');
$node->setAttribute('status', $task->status);
$dom->appendChild($node);
die($dom->saveXML());
}
$ret = $task->get_AllInfos();
header('Content-Type: text/xml; charset=utf-8');
die($ret['stdout']);
}
示例10: CreateXML
static function CreateXML($DataArray)
{
$dom = new DomDocument('1.0');
$element = $dom->appendChild($dom->createElement('element'));
$elementObject = $element->appendChild($dom->createElement('elementObject'));
foreach ($DataArray as $key => $value) {
if (!is_array($value)) {
$param = $elementObject->appendChild($dom->createElement(MyExtention::xml_check($key)));
$param->appendChild($dom->CreateTextNode(MyExtention::xml_check($value)));
} elseif ($key == "images") {
$elementImages = $elementObject->appendChild($dom->createElement(MyExtention::xml_check($key)));
foreach ($value as $subkey => $subvalue) {
$elementImage = $elementImages->appendChild($dom->createElement('image'));
$elementImage->appendChild($dom->CreateTextNode("http://www.ikea.com" . MyExtention::xml_check($subvalue)));
}
} elseif ($key == "category") {
$elementCategories = $elementObject->appendChild($dom->createElement('elementCategories'));
foreach ($value as $subkey => $subvalue) {
if ($subvalue != "Домой") {
$elementCategory = $elementCategories->appendChild($dom->createElement('elementCategory'));
$elementCategory->appendChild($dom->CreateTextNode(MyExtention::xml_check($subvalue)));
}
}
}
}
$dom->formatOutput = true;
$resultXML = $dom->saveXML();
return $resultXML;
}
示例11: getPreview
public function getPreview($elements)
{
if (!isset($this->preview)) {
if (!isset($elements)) {
$elements = 2;
}
// Get just the text (no markup) from a node using $node->textContent.
// Compare the textContent value to the one returned by $node->nodeValue.
libxml_use_internal_errors(true);
$dom = new DomDocument();
$dom->preserveWhiteSpace = false;
$dom->loadHTML('<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head><body>' . $this->Body . '</body></html>');
$dom->normalize();
$nodes = $dom->getElementsByTagName("body")->item(0)->childNodes;
$elementCount = 0;
$this->preview = '';
foreach ($nodes as $node) {
if ($node->nodeType === XML_ELEMENT_NODE) {
$this->preview .= $dom->saveXML($node);
$elementCount++;
if ($elementCount === $elements) {
break;
}
}
}
// Carriage returns in the XML prevent the markup from validating. -- cwells
$this->preview = str_replace(' ', '', $this->preview);
}
return $this->preview;
}
示例12: 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();
}
示例13: header
function upcoming_events()
{
header('Content-Type: ' . feed_content_type('rss-http') . '; charset=' . get_option('blog_charset'), true);
$xml = new DomDocument();
$xml->loadXML($this->get_upcoming_events());
echo $xml->saveXML();
}
示例14: format
function format($xml)
{
$dom = new DomDocument();
$dom->loadXML($xml);
$dom->formatOutput = true;
return $dom->saveXML();
}
示例15: 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;
}