本文整理汇总了PHP中DOMImplementation类的典型用法代码示例。如果您正苦于以下问题:PHP DOMImplementation类的具体用法?PHP DOMImplementation怎么用?PHP DOMImplementation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DOMImplementation类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: exportCoursesToXML
public function exportCoursesToXML()
{
$imp = new DOMImplementation();
$dtd = $imp->createDocumentType('kurse', '', 'http://dl.dropbox.com/u/357576/saves/dtd/course.dtd');
$doc = $imp->createDocument('', '', $dtd);
$doc->formatOutput = true;
$doc->encoding = "utf-8";
$doc->version = "1.0";
$pi = $doc->createProcessingInstruction("xml-stylesheet", "type=\"text/css\" href=\"http://dl.dropbox.com/u/357576/saves/dtd/course.css\"");
$doc->appendChild($pi);
$r = $doc->createElement("kurse");
$doc->appendChild($r);
$courses = $this->db->model('kurse')->select()->execute()->result;
foreach ($courses as $course) {
$k = $doc->createElement("kurs");
$course_id = $doc->createElement("kursId");
$course_id->appendChild($doc->createTextNode($course['id']));
$k->appendChild($course_id);
$course_name = $doc->createElement("kursname");
$course_name->appendChild($doc->createTextNode($course['kursname']));
$k->appendChild($course_name);
$semester = $doc->createElement("semester");
$semester->appendChild($doc->createTextNode($course['semester']));
$k->appendChild($semester);
$r->appendChild($k);
}
return $doc->saveXML();
}
示例2: __invoke
/**
* Array to XML markup.
*
* @since 160829.74007 XML conversion utils.
*
* @param string $parent_element_name Parent element name.
* @param array $array Input array to convert.
* @param array $args Any additional behavioral args.
*
* @return string XML or HTML (with or w/o a DOCTYPE tag).
*
* @note `<!DOCTYPE html>` is an HTML DOCTYPE tag.
* @note `<?xml version="1.0" encoding="utf-8"?>` is an XML DOCTYPE tag.
*/
public function __invoke(string $parent_element_name, array $array, array $args = []) : string
{
$default_args = ['type' => 'xml', 'version' => '1.0', 'encoding' => 'utf-8', 'include_doctype' => true, 'format' => true];
$args += $default_args;
// Merge w/ defaults.
$args['type'] = (string) $args['type'];
$args['version'] = (string) $args['version'];
$args['encoding'] = (string) $args['encoding'];
$args['include_doctype'] = (bool) $args['include_doctype'];
$args['format'] = (bool) $args['format'];
if ($args['type'] === 'html') {
$DOMImplementation = new \DOMImplementation();
$DOMDocumentType = $DOMImplementation->createDocumentType($args['type']);
$DOMDocument = $DOMImplementation->createDocument('', '', $DOMDocumentType);
} else {
$DOMDocument = new \DOMDocument($args['version']);
}
$DOMDocument->encoding = $args['encoding'];
$DOMDocument->formatOutput = $args['format'];
// Indentation.
$save = $args['type'] === 'html' ? 'saveHTML' : 'saveXML';
$ParentDOMElement = $DOMDocument->createElement($parent_element_name);
$DOMDocument->appendChild($ParentDOMElement);
$this->convert($DOMDocument, $ParentDOMElement, $array);
if (!$args['include_doctype']) {
return (string) $DOMDocument->{$save}($DOMDocument->documentElement);
} else {
return (string) $DOMDocument->{$save}();
// With doctype.
}
}
示例3: getResponse
/**
* create the response
*
* @return DOMDocument
*/
public function getResponse()
{
// Creates an instance of the DOMImplementation class
$imp = new DOMImplementation();
// Creates a DOMDocument instance
$document = $imp->createDocument("http://schemas.microsoft.com/exchange/autodiscover/mobilesync/requestschema/2006", 'Autodiscover');
$document->xmlVersion = '1.0';
$document->encoding = 'UTF-8';
$document->formatOutput = false;
$response = $document->documentElement->appendChild($document->createElement('Response'));
$user = $response->appendChild($document->createElement('User'));
$user->appendChild($document->createElement('EMailAddress', $this->emailAddress));
$settings = $document->createElement('Settings');
if (!empty($this->mobileSyncUrl)) {
$server = $document->createElement('Server');
$server->appendChild($document->createElement('Type', 'MobileSync'));
$server->appendChild($document->createElement('Url', $this->mobileSyncUrl));
$server->appendChild($document->createElement('Name', $this->mobileSyncUrl));
$settings->appendChild($server);
}
if (!empty($this->certEnrollUrl)) {
$server = $document->createElement('Server');
$server->appendChild($document->createElement('Type', 'CertEnroll'));
$server->appendChild($document->createElement('Url', $this->certEnrollUrl));
$server->appendChild($document->createElement('Name'));
$server->appendChild($document->createElement('ServerData', 'CertEnrollTemplate'));
$settings->appendChild($server);
}
if ($settings->hasChildNodes()) {
$action = $response->appendChild($document->createElement('Action'));
$action->appendChild($settings);
}
return $document;
}
示例4: toXmlString
public function toXmlString()
{
$impl = new DOMImplementation();
$docTypeName = 'uBookMessage';
$docTypePublic = '-//uBook/DTD uBookMessage 1//EN';
$docTypeId = WEBDIR . 'uBookMessage.dtd';
$docType = $impl->createDocumentType($docTypeName, $docTypePublic, $docTypeId);
$doc = $impl->createDocument('', '', $docType);
$doc->encoding = 'UTF-8';
$doc->xmlStandalone = false;
$message = $doc->createElement('uBookMessage');
$message->setAttribute('version', '1');
$message->setAttribute('from', $this->from);
$doc->appendChild($message);
foreach ($this->bookList as $i => $b) {
$book = $doc->createElement('book');
$book->setAttribute('url', $b->getUrl());
$book->setAttribute('author', $b->getAuthor());
$book->setAttribute('title', $b->getTitle());
$book->setAttribute('price', $b->getPrice());
$message->appendChild($book);
}
foreach ($this->servers as $i => $s) {
$server = $doc->createElement('server');
$server->setAttribute('url', $s->getUrl());
$message->appendChild($server);
}
$doc->formatOutput = true;
return $doc->saveXML();
}
示例5: toDOMDocument
/**
* @return \DOMDocument
*/
public function toDOMDocument()
{
$implementation = new \DOMImplementation();
$dtd = $implementation->createDocumentType('root', null, 'https://www.sode.pl/sode.dtd');
$dom = $implementation->createDocument('', '', $dtd);
$root = $dom->createElement('root');
$properties = $dom->importNode($this->getProperties()->toDOMElement(), true);
$client = $dom->importNode($this->getClient()->toDOMElementWithAttributes(), true);
$document = $dom->createElement('document');
$document->setAttribute('type', $this->getType());
$document->setAttribute('label', $this->getLabel());
$document->setAttribute('label_name', $this->getLabelName());
$document->setAttribute('notify', $this->getNotify());
$document->setAttribute('paid', $this->getPaid() ? 1 : 0);
$root->appendChild($document);
$document->appendChild($properties);
$document->appendChild($client);
$elements = $dom->createElement('elements');
foreach ($this->elements as $element) {
$elements->appendChild($dom->importNode($element->toDOMElement(), true));
}
if ($this->getAutoTotalEntry()) {
$elements->appendChild($dom->importNode($this->getTotalElement()->toDOMElement(), true));
}
$document->appendChild($elements);
$dom->formatOutput = true;
$dom->appendChild($root);
return $dom;
}
示例6: DOMImplementation
/**
* Create a new XML document.
* If $url is set, the DOCTYPE definition is treated as a PUBLIC
* definition; $dtd should contain the ID, and $url should contain the
* URL. Otherwise, $dtd should be the DTD name.
*/
function &createDocument($type = null, $dtd = null, $url = null)
{
$version = '1.0';
if (class_exists('DOMImplementation')) {
// Use the new (PHP 5.x) DOM
$impl = new DOMImplementation();
// only generate a DOCTYPE if type is non-empty
if ($type != '') {
$domdtd = $impl->createDocumentType($type, isset($url) ? $dtd : '', isset($url) ? $url : $dtd);
$doc = $impl->createDocument($version, '', $domdtd);
} else {
$doc = $impl->createDocument($version, '');
}
// ensure we are outputting UTF-8
$doc->encoding = 'UTF-8';
} else {
// Use the XMLNode class
$doc = new XMLNode();
$doc->setAttribute('version', $version);
if ($type !== null) {
$doc->setAttribute('type', $type);
}
if ($dtd !== null) {
$doc->setAttribute('dtd', $dtd);
}
if ($url !== null) {
$doc->setAttribute('url', $url);
}
}
return $doc;
}
示例7: getPlistString
public static function getPlistString($ipa, $bundleIdentifier, $version, $title)
{
$imp = new \DOMImplementation();
$dtd = $imp->createDocumentType("plist", "-//Apple//DTD PLIST 1.0//EN", "http://www.apple.com/DTDs/PropertyList-1.0.dtd");
$dom = $imp->createDocument("", "", $dtd);
$dom->encoding = "UTF-8";
$dom->formatOutput = true;
$dom->appendChild($element = $dom->createElement('plist'));
$element->setAttribute('version', '1.0');
$element->appendChild($dict = $dom->createElement('dict'));
$dict->appendChild($dom->createElement('key', 'items'));
$dict->appendChild($array = $dom->createElement('array'));
$array->appendChild($mainDict = $dom->createElement('dict'));
$mainDict->appendChild($dom->createElement('key', 'assets'));
$mainDict->appendChild($array = $dom->createElement('array'));
$array->appendChild($dict = $dom->createElement('dict'));
$dict->appendChild($dom->createElement('key', 'kind'));
$dict->appendChild($dom->createElement('string', 'software-package'));
$dict->appendChild($dom->createElement('key', 'url'));
$dict->appendChild($dom->createElement('string', $ipa));
$mainDict->appendChild($dom->createElement('key', 'metadata'));
$mainDict->appendChild($dict = $dom->createElement('dict'));
$dict->appendChild($dom->createElement('key', 'bundle-identifier'));
$dict->appendChild($dom->createElement('string', $bundleIdentifier));
$dict->appendChild($dom->createElement('key', 'bundle-version'));
$dict->appendChild($dom->createElement('string', $version));
$dict->appendChild($dom->createElement('key', 'kind'));
$dict->appendChild($dom->createElement('string', 'software'));
$dict->appendChild($dom->createElement('key', 'title'));
$dict->appendChild($titleElement = $dom->createElement('string'));
$titleElement->appendChild($dom->createTextNode($title . '-v.' . $version));
return $dom->saveXML();
}
示例8: testAppendXmlData
/**
* test xml generation for IPhone
*
* birthday must have 12 hours added
*/
public function testAppendXmlData()
{
$imp = new DOMImplementation();
$dtd = $imp->createDocumentType('AirSync', "-//AIRSYNC//DTD AirSync//EN", "http://www.microsoft.com/");
$testDoc = $imp->createDocument('uri:AirSync', 'Sync', $dtd);
$testDoc->formatOutput = true;
$testDoc->encoding = 'utf-8';
$appData = $testDoc->documentElement->appendChild($testDoc->createElementNS('uri:AirSync', 'ApplicationData'));
$email = new Syncroton_Model_FileReference(array('contentType' => 'text/plain', 'data' => 'Lars'));
$email->appendXML($appData, $this->_testDevice);
#echo $testDoc->saveXML();
$xpath = new DomXPath($testDoc);
$xpath->registerNamespace('AirSync', 'uri:AirSync');
$xpath->registerNamespace('AirSyncBase', 'uri:AirSyncBase');
$xpath->registerNamespace('Email', 'uri:Email');
$xpath->registerNamespace('Email2', 'uri:Email2');
$nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/AirSyncBase:ContentType');
$this->assertEquals(1, $nodes->length, $testDoc->saveXML());
$this->assertEquals('text/plain', $nodes->item(0)->nodeValue, $testDoc->saveXML());
$nodes = $xpath->query('//AirSync:Sync/AirSync:ApplicationData/ItemOperations:Data');
$this->assertEquals(1, $nodes->length, $testDoc->saveXML());
$this->assertEquals('TGFycw==', $nodes->item(0)->nodeValue, $testDoc->saveXML());
// try to encode XML until we have wbxml tests
$outputStream = fopen("php://temp", 'r+');
$encoder = new Syncroton_Wbxml_Encoder($outputStream, 'UTF-8', 3);
$encoder->encode($testDoc);
}
示例9: __construct
/**
* Constructor
*
* @param HTMLTree $tree
*/
public function __construct(HTMLTree $tree)
{
$this->_tree = $tree;
$dom_implementation = new \DOMImplementation();
$doc_type = $dom_implementation->createDocumentType('html', '', '');
$this->_dom = $dom_implementation->createDocument('', 'html', $doc_type);
$this->_dom->documentElement->setAttribute('lang', 'en');
}
示例10: doctype
public static function doctype($docid, $object = false)
{
$doctypes = array(self::HTML_4_STR => array("HTML", "-//W3C//DTD HTML 4.01//EN", "http://www.w3.org/TR/html4/strict.dtd"), self::HTML_4_TRA => array("HTML", "-//W3C//DTD HTML 4.01 Transitional//EN", "http://www.w3.org/TR/html4/loose.dtd"), self::HTML_4_FRA => array("HTML", "-//W3C//DTD HTML 4.01 Frameset//EN", "http://www.w3.org/TR/html4/frameset.dtd"), self::XHTML_1_STR => array("HTML", "-//W3C//DTD XHTML 1.0 Strict//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"), self::XHTML_1_TRA => array("HTML", "-//W3C//DTD XHTML 1.0 Transitional//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"), self::XHTML_1_FRA => array("HTML", "-//W3C//DTD XHTML 1.0 Frameset//EN", "http://www.w3.org/TR/xhtml1/DTD/xhtml1-frameset.dtd"), self::XHTML_1_1 => array("HTML", "-//W3C//DTD XHTML 1.1//EN", "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"), self::XHTML_1_BASIC => array("HTML", "-//W3C//DTD XHTML Basic 1.1//EN", "http://www.w3.org/TR/xhtml-basic/xhtml-basic11.dtd"), self::HTML_5 => array("HTML", "", ""), self::MATHML_1 => array("MATH", "", "http://www.w3.org/Math/DTD/mathml1/mathml.dtd"), self::MATHML_2 => array("MATH", "-//W3C//DTD MathML 2.0//EN", "http://www.w3.org/Math/DTD/mathml2/mathml2.dtd"));
$implementation = new \DOMImplementation();
$dtd = $implementation->createDocumentType($doctypes[$docid][0], $doctypes[$docid][1], $doctypes[$docid][2]);
$document = $implementation->createDocument('', '', $dtd);
return $object ? $document : $document->saveHTML();
}
示例11: __construct
/**
* init your xhtml document.
*
* @access public
* @return void
*/
public function __construct()
{
$domImplementation = new DOMImplementation();
$doctype = $domImplementation->createDocumentType('html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
$this->document = $domImplementation->createDocument('http://www.w3.org/1999/xhtml', 'html', $doctype);
$this->head = $this->document->createElement('head');
$this->body = $this->document->createElement('body');
$this->setTitle(null);
$this->setTitleAppend(null);
}
示例12: on_create
protected function on_create()
{
$impl = new DOMImplementation();
$dtd = $impl->createDocumentType('html', '-//W3C//DTD XHTML 1.0 Strict//EN', 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd');
$doc = $impl->createDocument($this->ccnamespaces[$this->rootns], null, $dtd);
$doc->formatOutput = true;
$doc->preserveWhiteSpace = true;
$this->doc = $doc;
parent::on_create();
}
示例13: __construct
function __construct($config)
{
$this->config = $config;
$imp = new DOMImplementation();
$dtd = $imp->createDocumentType('OPS_envelope', '', 'ops.dtd');
$dom = $imp->createDocument("", "", $dtd);
$dom->encoding = 'UTF-8';
$dom->standalone = false;
$this->xml = $dom;
}
示例14: initializeDocument
/**
* Initialize destination document
*
* Initialize the structure which the destination document could be build
* with. This may be an initial DOMDocument with some default elements, or
* a string, or something else.
*
* @return mixed
*/
protected function initializeDocument()
{
$imp = new DOMImplementation();
$dtd = $imp->createDocumentType('article', '-//OASIS//DTD DocBook XML V4.5//EN', 'http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd');
$docbook = $imp->createDocument('http://docbook.org/ns/docbook', '', $dtd);
$docbook->formatOutput = true;
$root = $docbook->createElementNs('http://docbook.org/ns/docbook', 'article');
$docbook->appendChild($root);
return $root;
}
示例15: createDomDocument
public function createDomDocument()
{
$impl = new DOMImplementation();
$dtd = $impl->createDocumentType('docman', '', get_server_url() . '/plugins/docman/docman-1.0.dtd');
$doc = $impl->createDocument('', '', $dtd);
$doc->encoding = 'UTF-8';
$doc->standalone = 'no';
$doc->version = '1.0';
$doc->formatOutput = true;
return $doc;
}