本文整理汇总了PHP中domDocument::createElementNS方法的典型用法代码示例。如果您正苦于以下问题:PHP domDocument::createElementNS方法的具体用法?PHP domDocument::createElementNS怎么用?PHP domDocument::createElementNS使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类domDocument
的用法示例。
在下文中一共展示了domDocument::createElementNS方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addElement
/**
* Adds an child element to the parent
* @param string The name element
* @param domNode
* @return domNode
*/
private function addElement($name, $parent = false, $ns = false)
{
if ($ns) {
$el = $this->doc->createElementNS($ns, $name);
} else {
$el = $this->doc->createElement($name);
}
if ($parent) {
$parent->appendChild($el);
}
return $el;
}
示例2: domDocument
<?php
$document = new domDocument("1.0", "utf-8");
$domimp = new domImplementation();
$doctype = $domimp->createDocumentType('asortiment[<!ENTITY y1 "2009"> <!ENTITY y2 "2010">]');
$document->appendChild($doctype);
$asortiment = $document->createElementNS("http://mysite.ru", "asort:asortiment");
$document->appendChild($asortiment);
$telefon = $document->createElement("asort:telefon");
$asortiment->appendChild($telefon);
$attr = $document->createAttribute("number");
$attr->nodeValue = 1;
$telefon->appendChild($attr);
$cdata = $document->createCDATASection("Это контент нашего интернет магазина");
$telefon->appendChild($cdata);
$model_1 = $document->createElement("model");
$telefon->appendChild($model_1);
$name_1 = $document->createElement("name");
$model_1->appendChild($name_1);
$textN_1 = $document->createTextNode("Samsung Galaxi");
$name_1->appendChild($textN_1);
$year_1 = $document->createElement("year");
$model_1->appendChild($year_1);
$textY_1 = $document->createTextNode('2009');
$year_1->appendChild($textY_1);
$model_2 = $document->createElement("model");
$telefon->appendChild($model_2);
$name_2 = $document->createElement("name");
$model_2->appendChild($name_2);
$textN_2 = $document->createTextNode("Nokia Lumia");
$name_2->appendChild($textN_2);
示例3: domDocument
try {
$dom = new domDocument();
$dom->createElementNS('http://www.w3.org/2000/xmlns/', 'xmlns:valid');
print "valid\n";
} catch (Exception $e) {
print $e->getMessage() . "\n";
}
print "33 DOMElement::__construct('xmlns:valid', '', 'http://www.w3.org/2000/xmlns/')\n";
try {
$element = new DomElement('xmlns:valid', '', 'http://www.w3.org/2000/xmlns/');
print "valid\n";
} catch (Exception $e) {
print $e->getMessage() . "\n";
}
/* the namespaceURI is "http://www.w3.org/2000/xmlns/" and neither the
qualifiedName nor its prefix is "xmlns". */
print "34 DOMDocument::createElementNS('http://www.w3.org/2000/xmlns/', 'wrongprefix:valid')\n";
try {
$dom = new domDocument();
$dom->createElementNS('http://www.w3.org/2000/xmlns/', 'wrongprefix:valid');
print "valid\n";
} catch (Exception $e) {
print $e->getMessage() . "\n";
}
print "35 DOMElement::__construct('wrongprefix:valid', '', 'http://www.w3.org/2000/xmlns/')\n";
try {
$element = new DomElement('wrongprefix:valid', '', 'http://www.w3.org/2000/xmlns/');
print "valid\n";
} catch (Exception $e) {
print $e->getMessage() . "\n";
}