本文整理汇总了PHP中DOMDocument::importNode方法的典型用法代码示例。如果您正苦于以下问题:PHP DOMDocument::importNode方法的具体用法?PHP DOMDocument::importNode怎么用?PHP DOMDocument::importNode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DOMDocument
的用法示例。
在下文中一共展示了DOMDocument::importNode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1:
function insert_node(DOMDocument &$doc, DOMElement &$field_elem, SimpleXMLElement $details_xml)
{
$travel_res_submitted_fields = dom_import_simplexml($details_xml->travel_res_submitted_fields[0]);
//$travel_res_submitted_fields = $doc->createElement("travel_res_submitted_fields");
$dom_sxe = $doc->importNode($travel_res_submitted_fields, true);
$field_elem->appendChild($dom_sxe);
if ($details_xml->travel_product[0])
{
$travel_res_product = dom_import_simplexml($details_xml->travel_product[0]);
//$travel_res_submitted_fields = $doc->createElement("travel_res_submitted_fields");
$dom_sxe = $doc->importNode($travel_res_product, true);
$field_elem->appendChild($dom_sxe);
}
if ($details_xml->travel_lookups[0])
{
$travel_res_product_lookups = dom_import_simplexml($details_xml->travel_lookups[0]);
//$travel_res_submitted_fields = $doc->createElement("travel_res_submitted_fields");
$dom_sxe_lkp = $doc->importNode($travel_res_product_lookups, true);
$field_elem->appendChild($dom_sxe_lkp);
}
}
示例2: addSortableScriptOnGrid
/**
* Appends the "sortable" js code to the bottom of ajax-Request for the category-products loaded after
* changing sort order.
*
* @param Varien_Event_Observer $observer
*/
public function addSortableScriptOnGrid(Varien_Event_Observer $observer)
{
$_block = $observer->getBlock();
$_type = $_block->getType();
if (Mage::helper('ffuenf_categoryproductsortbackend')->isExtensionActive() && $_type == 'adminhtml/catalog_category_tab_product') {
$content = $observer->getTransport()->getHtml();
$dom = new DOMDocument('1.0', 'utf-8');
$doc = new DOMDocument('1.0', 'utf-8');
$dom->loadHTML(mb_convert_encoding($content, 'HTML-ENTITIES', 'UTF-8'));
foreach ($dom->getElementsByTagName('select') as $element) {
if ($element->getAttribute('name') == 'limit') {
$option = $dom->createElement('option');
$option->appendChild($dom->createTextNode('All'));
$option->setAttribute('value', 0);
$option = $element->appendChild($option);
}
}
$additionalHtml = $this->appendScript($content);
$additionalDoc = new DOMDocument();
$additionalDoc->loadHTML($additionalHtml);
$additionalDocScript = $additionalDoc->getElementsByTagName('script')->item(0);
$body = $dom->getElementsByTagName('body')->item(0);
foreach ($body->childNodes as $child) {
$doc->appendChild($doc->importNode($child, true));
}
$doc->appendChild($doc->importNode($additionalDocScript, true));
$content = $doc->saveHTML();
$observer->getTransport()->setHtml($content);
}
}
示例3: processHtml
/**
* {@inheritDoc}
*/
public function processHtml($html, \DOMNode $container = null, &$replacedCount = null)
{
$urlRegExpr = $this->getRegExpression();
$linkRegexp = "/<a href=\"{$urlRegExpr}\">{$urlRegExpr}<\\/a>/i";
$document = new \DOMDocument();
if (!$container) {
$container = $document;
} else {
$container = $document->importNode($container);
}
return preg_replace_callback($linkRegexp, function ($matches) use($document, $container) {
$matches = array_map('html_entity_decode', $matches);
while ($container->hasChildNodes()) {
$container->removeChild($container->firstChild);
}
$embedNodes = $this->getEmbedNodes($matches);
if (!is_array($embedNodes)) {
$embedNodes = [$embedNodes];
}
foreach ($embedNodes as $embedNode) {
$container->appendChild($document->importNode($embedNode, true));
}
return $document->saveHTML($container);
}, $html, -1, $replacedCount);
}
示例4: debugXML
/**
* Print an xml.
*
* @param DOMNodeList or DOMElement $m the object to be printed.
*
* @return void.
*/
public static function debugXML($m)
{
$out = new DOMDocument();
$root = $out->createElement('debugxml');
switch (get_class($m)) {
case "DOMNodeList":
foreach ($m as $domElement) {
$dom_sxe = $out->importNode($domElement, true);
$root->appendChild($dom_sxe);
}
break;
case "DOMElement":
$dom_sxe = $out->importNode($m, true);
$root->appendChild($dom_sxe);
break;
case "XMLDom":
$dom_sxe = $out->importNode($m->firstChild, true);
$root->appendChild($dom_sxe);
break;
default:
throw new Exception("Object type " . get_class($m) . ' can not be converted to xml.', 1);
break;
}
$out->appendChild($root);
header("Content-type:text/xml");
echo $out->saveXML();
}
示例5: build
public function build()
{
$this->doc = new \DOMDocument('1.0', 'UTF-8');
if ($this->structure) {
$this->doc->appendChild($this->doc->importNode(dom_import_simplexml($this->structure), true));
}
}
示例6: static__escaped_fragment_
public static function static__escaped_fragment_($_escaped_fragment_)
{
\libxml_use_internal_errors(true);
$html = new \DOMDocument();
$html->loadHTML(static::default_page($_escaped_fragment_ ? $_escaped_fragment_ : true));
if ($error = \libxml_get_last_error()) {
//new \SYSTEM\LOG\ERROR('Parse Error: '.$error->message.' line:'.$error->line.' html: '.$html->saveHTML());
\libxml_clear_errors();
}
$state = \SYSTEM\PAGE\State::get(static::get_apigroup(), $_escaped_fragment_ ? $_escaped_fragment_ : static::get_default_state(), false);
foreach ($state as $row) {
$frag = new \DOMDocument();
parse_str(\parse_url($row['url'], PHP_URL_QUERY), $params);
$class = static::get_class($params);
if ($class) {
$frag->loadHTML(\SYSTEM\API\api::run('\\SYSTEM\\API\\verify', $class, static::get_params($params), static::get_apigroup(), true, false));
if ($error = \libxml_get_last_error()) {
//new \SYSTEM\LOG\ERROR('Parse Error: '.$error->message.' line:'.$error->line.' html: '.$frag->saveHTML());
\libxml_clear_errors();
}
$html->getElementById(substr($row['div'], 1))->appendChild($html->importNode($frag->documentElement, true));
//Load subpage css
foreach ($row['css'] as $css) {
$css_frag = new \DOMDocument();
$css_frag->loadHTML('<link href="' . $css . '" rel="stylesheet" type="text/css">');
$html->getElementsByTagName('head')[0]->appendChild($html->importNode($css_frag->documentElement, true));
}
}
}
echo $html->saveHTML();
new \SYSTEM\LOG\COUNTER("API was called sucessfully.");
die;
}
示例7: add
/**
* @param Sitemap_URL $object
*/
public function add(Sitemap_URL $object)
{
$url = $object->create();
// Decorate the urlset
$object->root($this->_root);
// Append URL to root element
$this->_root->appendChild($this->_xml->importNode($url, TRUE));
}
示例8: __construct
/**
* Constructor.
*
* @param \DOMNode $node The node associated with this field
*/
public function __construct(\DOMNode $node)
{
$this->node = $node;
$this->name = $node->getAttribute('name');
$this->document = new \DOMDocument('1.0', 'UTF-8');
$this->node = $this->document->importNode($this->node, true);
$root = $this->document->appendChild($this->document->createElement('_root'));
$root->appendChild($this->node);
$this->xpath = new \DOMXPath($this->document);
$this->initialize();
}
示例9: addRole
public function addRole($name)
{
$role = new \DOMDocument('1.0', 'UTF-8');
$role->load(__DIR__ . '/../Resources/role_template/RoleConfig.xml');
$roles = $role->getElementsByTagName('Role');
$roleNode = $roles->item(0);
$roleNode->setAttribute('name', $name);
$roleNode = $this->dom->importNode($roleNode, true);
$this->dom->documentElement->appendChild($roleNode);
if ($this->dom->save($this->serviceConfigurationFile) === false) {
throw new \RuntimeException(sprintf("Could not write ServiceConfiguration to '%s'", $this->serviceConfigurationFile));
}
}
示例10: appendChild
/**
* @param \DiDom\Element|\DOMNode $element
* @return \DiDom\Element
* @throws \InvalidArgumentException
*/
public function appendChild($element)
{
if ($element instanceof Element) {
$element = $element->getElement();
}
if (!$element instanceof DOMNode) {
throw new InvalidArgumentException(sprintf('Argument 1 passed to %s must be an instance of %s\\Element or %s, %s given', __METHOD__, __NAMESPACE__, 'DOMNode', is_object($element) ? get_class($element) : gettype($element)));
}
$cloned = $element->cloneNode(true);
$temp = $this->document->importNode($cloned, true);
$this->document->appendChild($temp);
return $this;
}
示例11: selectNodeType
/**
* Tests the value being passed and decide what sort of element to create.
*
* @param \DOMNode $node
* @param mixed $val
*
* @return bool
*/
private function selectNodeType(\DOMNode $node, $val)
{
if (is_array($val)) {
return $this->buildXml($node, $val);
} elseif ($val instanceof \SimpleXMLElement) {
$child = $this->dom->importNode(dom_import_simplexml($val), true);
$node->appendChild($child);
} elseif ($val instanceof \Traversable) {
$this->buildXml($node, $val);
} elseif (is_object($val)) {
return $this->buildXml($node, $this->serializer->normalize($val, $this->format));
} elseif (is_numeric($val)) {
return $this->appendText($node, (string) $val);
} elseif (is_string($val) && $this->needsCdataWrapping($val)) {
return $this->appendCData($node, $val);
} elseif (is_string($val)) {
return $this->appendText($node, $val);
} elseif (is_bool($val)) {
return $this->appendText($node, (int) $val);
} elseif ($val instanceof \DOMNode) {
$child = $this->dom->importNode($val, true);
$node->appendChild($child);
}
return true;
}
示例12: array
function get_properties_change_history_records_xml()
{
$eids = array();
$xml_string = "";
$sql = "select eid from view_int_prop_to_e_p_to_e\nwhere type_id in (select type_id from type where type_name like '%_history') and prop_id = 40 and int_val = " . $this->eid;
$result = mysql_query($sql) or die("Error in RecordHistory...3lkd0skdjskfklk" . mysql_error());
while ($row = mysql_fetch_assoc($result)) {
$eids[] = $row['eid'];
}
$doc = new DOMDocument('1.0', 'UTF-8');
$doc->formatOutput = true;
$recs = $doc->createElement('records');
$recs = $doc->appendChild($recs);
foreach ($eids as $eid) {
$type_id = RecordsSys_EntityManagementSystems::get_type_id($eid);
$rec = new Record($eid, $type_id);
$rec->initialize();
$xml_string = $rec->xml_string;
$doc2 = new DOMDocument('1.0', 'UTF-8');
$doc2->loadXML($xml_string);
$node = $doc->importNode($doc2->firstChild, true);
$recs->appendChild($node);
}
// $rec->glu->prop_ids_num_extra[6] = 1;
// $rec->glu->set_prop_ids_num_extra_by_group_id(1);
//$rec->glu->set_prop_ids_num_extra_by_group_id(1);
// $xslt_file = $_SERVER['DOCUMENT_ROOT']."/XSLTemplates/testrecs.xsl";
$xml_string = $doc->saveXML();
return $xml_string;
}
示例13: getChildElements
/**
* Get the child objects
* and render them as document fragment
*
* @param \DOMDocument $dom DOMDocument
* @return \DOMDocumentFragment
*/
public function getChildElements(\DOMDocument $dom)
{
$modelChildren = $this->model->getElements();
$documentFragment = NULL;
foreach ($modelChildren as $key => $modelChild) {
$child = $this->createChildElementFromModel($modelChild);
if ($child) {
if ($child->noWrap() === TRUE) {
$childNode = $child->render();
} else {
$childNode = $child->render('elementWrap');
if ($childNode) {
$childNode->setAttribute('class', $child->getElementWraps());
}
}
if ($childNode) {
$importedNode = $dom->importNode($childNode, TRUE);
if (!$documentFragment) {
$documentFragment = $dom->createDocumentFragment();
}
$documentFragment->appendChild($importedNode);
}
}
}
return $documentFragment;
}
示例14: innerHTML
public static function innerHTML($node)
{
$document = new DOMDocument();
$node = $document->importNode($node, true);
$document->appendChild($node);
return $document->saveHTML($node);
}
示例15: getXCal
/**
* Erstellt aus der Liste der Events ein vollständiges XML Dokument.
* Die Ausgabe erfolgt wahlweise als XML-Zeichenkette oder als DOMDocument-Objekt.
*
* @param Array $vEventArray Liste der vevent DOMElemente
* @param String $format "XML"|"DOMElement"
* @return String|DOMElement
* @throws Exception
*/
public static function getXCal($vEventArray, $format = "XML")
{
// Struktur
$xmlDocument = new DOMDocument("1.0", "UTF-8");
$root = $xmlDocument->appendChild($xmlDocument->createElement("icalendar"));
$vCalendar = $root->appendChild($xmlDocument->createElement("vcalendar"));
$vCalendar->appendChild($xmlDocument->createElement("prodid", "-//Mozilla.org/NONSGML Mozilla Calendar V 1.0 //EN"));
$vCalendar->appendChild($xmlDocument->createElement("version", "2.0"));
// Eventliste
foreach ($vEventArray as $i => $vEvent) {
if (get_class($vEvent) !== "DOMElement") {
throw new Exception("Unknown type in vEventArray at position " . $i);
}
$vEvent = $xmlDocument->importNode($vEvent, true);
$vCalendar->appendChild($vEvent);
}
// Rückgabe
switch ($format) {
case "XML":
return $xmlDocument->saveXML();
break;
case "DOMElement":
return $root;
break;
default:
throw new Exception("Unknown output format");
break;
}
}