public function addProcessingInstruction($target, $data = NULL) { $node = dom_import_simplexml($this); $pi = $node->ownerDocument->createProcessingInstruction($target, $data); $result = $node->insertBefore($pi, $node->childNodes->item(0)); return $this; }
/** * Add a child element; this corrects CDATA issues * * @throws RuntimeException */ public function addChild($name, $value = NULL, $namespace = NULL) { if ($this->isCData($value) || $this->getConfig('autoCData', FALSE) && $this->wrapCData($value)) { // Stash a CDATA value for later... $valueAsCData = $value; $value = NULL; } elseif ($this->getConfig('autoEntities', FALSE)) { $this->xmlChars($value); } $child = parent::addChild($name, $value, $namespace); // switch (func_num_args()) { // case 1: // $child = parent::addChild($name); // break; // case 2: // $child = parent::addChild($name, $value); // break; // case 3: // $child = parent::addChild($name, $value, $namespace); // break; // } if (isset($valueAsCData)) { $node = dom_import_simplexml($child); $no = $node->ownerDocument; $value = self::stripCData($valueAsCData); $node->appendChild($no->createCDATASection($value)); } return $child; }
/** * Render a Zend_Config into a XML config string. * * @since 1.10 * @return string */ public function render() { $xml = new SimpleXMLElement('<zend-config xmlns:zf="' . Zend_Config_Xml::XML_NAMESPACE . '"/>'); $extends = $this->_config->getExtends(); $sectionName = $this->_config->getSectionName(); if (is_string($sectionName)) { $child = $xml->addChild($sectionName); $this->_addBranch($this->_config, $child, $xml); } else { foreach ($this->_config as $sectionName => $data) { if (!$data instanceof Zend_Config) { $xml->addChild($sectionName, (string) $data); } else { $child = $xml->addChild($sectionName); if (isset($extends[$sectionName])) { $child->addAttribute('zf:extends', $extends[$sectionName], Zend_Config_Xml::XML_NAMESPACE); } $this->_addBranch($data, $child, $xml); } } } $dom = dom_import_simplexml($xml)->ownerDocument; $dom->formatOutput = true; $xmlString = $dom->saveXML(); return $xmlString; }
public static function prettyPrint($data, $rootNodeName = 'data') { $xml = self::_recursiveXmlEncode($data, $rootNodeName); $dom = dom_import_simplexml($xml)->ownerDocument; $dom->formatOutput = true; return $dom->saveXML(); }
private function replaceChildNode(SimpleXMLElement $target, SimpleXMLElement $replacement) { $target_dom = dom_import_simplexml($target); $replacement_dom = $target_dom->ownerDocument->importNode(dom_import_simplexml($replacement), true); $p = $target_dom->parentNode; return $p->replaceChild($replacement_dom, $target_dom); }
public function saveAction() { $filepath = Mage::getBaseDir("skin") . DS . "frontend" . DS . "default" . DS . "default" . DS . "css" . DS . 'option.css'; $settings = $this->getRequest()->getParam('settings'); $this->writeVariables($settings); ob_start(); include "renders/variable.php"; include "renders/css.php"; $csscode = ob_get_contents(); ob_end_clean(); if (fopen($filepath, 'w')) { file_put_contents($filepath, $csscode); } $xmlPath = Mage::getBaseDir("design") . DS . "frontend" . DS . "base" . DS . "default" . DS . "layout" . DS . 'jmbasetheme.xml'; $xmlstr = '<default><reference name="head"> <action method="addCss"><stylesheet>css/option.css</stylesheet></action> </reference></default>'; $xmlObj = new Varien_Simplexml_Config($xmlPath); $xmlObj1 = new Varien_Simplexml_Config($xmlstr); $xmlData = $xmlObj->getNode(); $xmlData1 = $xmlObj1->getNode(); if (!$xmlData->descend("default/reference@name=head")) { $reference = $xmlData->appendChild($xmlData1); file_put_contents($xmlPath, $xmlData->asNiceXml()); } else { $oNode = dom_import_simplexml($xmlData->default); $oNode->parentNode->removeChild($oNode); file_put_contents($xmlPath, $xmlData->asNiceXml()); } $this->_redirect('*/*/'); }
public function testLastChild() { $root = new SimpleDOM('<root><child1 /><child2 /><child3 /></root>'); $child2 = $root->child3->previousSibling(); $this->assertTrue($child2 instanceof SimpleDOM); $this->assertSame(dom_import_simplexml($root->child2), dom_import_simplexml($child2)); }
public function addNodeToParent(\SimpleXMLElement $xmlNode, $parent) { $domNode = dom_import_simplexml($xmlNode); $node = $this->xmlDocument->importNode($domNode, TRUE); $parentElement = $this->xmlDocument->getElementsByTagName($parent); $parentElement->item(0)->appendChild($node); }
public function testGrandchild() { $root = new SimpleDOM('<root><child><grandchild /></child></root>'); $parent = $root->child->grandchild->parentNode(); $this->assertTrue($parent instanceof SimpleDOM); $this->assertSame(dom_import_simplexml($root->child), dom_import_simplexml($parent)); }
public function testIsChainable() { $node = new SimpleDOM('<node />'); $return = $node->setAttributes(array()); $this->assertEquals($node, $return); $this->assertTrue(dom_import_simplexml($node)->isSameNode(dom_import_simplexml($return))); }
function analyzeSchematronIssues($SchematronIssuesReport) { //$schematronIssue = array(new SchematronIssues); $reportStartString = "<svrl:failed-assert"; $reportEndString = "</svrl:failed-assert>"; $schematronIssue[0]->text = ""; $schematronIssue[0]->location = ""; $schematronIssue[0]->attributes = ""; $reportXML = extractStringBetweenTokens($SchematronIssuesReport, $reportStartString, $reportEndString); $reportXML = str_replace("svrl:", "", $reportXML); $reportXML = str_replace("failed-assert", "assert", $reportXML); $reportXML = "<repots>" . $reportXML . "</repots>"; $sxe = simplexml_load_string($reportXML); $dom_sxe = new DOMDocument('1.0'); $dom_sxe = dom_import_simplexml($sxe); $numErrors = sizeof($sxe); for ($i = 0; $i < $numErrors; $i++) { $errorElement = $dom_sxe->getElementsByTagName('assert')->item($i); // access the parent "MPD" in mpd file $schematronIssue[$i]->text = getSchemaErrorText($errorElement); $schematronIssue[$i]->location = getSchemaErrorLocation($errorElement); // get mediapersentation duration from mpd level $schematronIssue[$i]->attributes = getSchemaErrorAttributes($errorElement); // get mediapersentation duration from mpd level //$SchematronErrorLocations[] = getSchemaErrorLocation($errorElement->getAttribute('location')); // get mediapersentation duration from mpd level } return $schematronIssue; }
public function testGrandchild() { $root = new SXE('<root><child1 /><child2 /><child3><grandchild /></child3></root>'); $grandchild = $root->child3->lastChild(); $this->assertTrue($grandchild instanceof SXE); $this->assertSame(dom_import_simplexml($root->child3->grandchild), dom_import_simplexml($grandchild)); }
/** hack to Just Get A Question from current dmid, using Excercise class * to do our factorying for us. * Obviously the factory code needs to be refactored to ElseWhere, but not on Sunday * :-P * (Sun 15 Jun 2008) */ function getQuestion( $dmid, $questionLanguages, $answerLanguages ) { if ( !$questionLanguages ) throw new Exception( "Vocview: no question (original) languages provided!" ); if ( !$answerLanguages ) throw new Exception( "Vocview: no answer (translation) languages provided!" ); /* 3 men walked into a bar^wExercise * fullset, fetcher, and subset */ /* our regular fetcher is provided by functions.php * I suppose if I were tidier, I could use fetchers for * persistence */ $fetcher = new OWFetcher(); /* fullset is a domdocument containing a <collection> of * empty <defined-meanings/> (just their defined-meaning-id * attribute is set) * This format makes sense on some days, it's just * massive nukular overkill today, specially since * we only have 1 element :-P * Still, if Exercise wants this as a dom, we can oblige. */ $xmlString = " <collection> <defined-meaning defined-meaning-id=\"$dmid\" /> </collection> "; $xml = simplexml_load_string( $xmlString ); $fullset = dom_import_simplexml( $xml )->ownerDocument; # et voila. /* subset is a selection of stuff we are actually * interested in, from the above, as an array of * dmid's .... Oh look! We have just one! */ $subset = array( $dmid ); # :-P # (ok, to be honest, it does also get auto-generated # from the fullset, if we say nothing... but # then where would the joke be? ) # and we already had the fetcher. # So the fullset said to the fetcher: let's do this! $exercise = new Exercise( $fetcher, $fullset, $subset ); $exercise->setQuestionLanguages( $questionLanguages ); $exercise->setAnswerLanguages( $answerLanguages ); # Ok, now let's see. which question did we need? # (and setting selfcheck to false) $question = $exercise->getQuestion( $dmid, false ); # Oh REALLY! And we needed to go through all that? # well, let's return it, before people start asking # more difficult questions. return $question; }
/** * Create a dom document based on a SimpleXMLElement * * @param SimpleXMLElement $xml_element * * @return \DOMDocument */ private function simpleXmlElementToDomDocument(SimpleXMLElement $xml_element) { $dom = new DOMDocument("1.0", "UTF-8"); $dom_element = $dom->importNode(dom_import_simplexml($xml_element), true); $dom->appendChild($dom_element); return $dom; }
public function addCData($nodename, $cdata_text) { $node = $this->addChild($nodename); $node = dom_import_simplexml($node); $no = $node->ownerDocument; $node->appendChild($no->createCDATASection($cdata_text)); }
function addTax(SimpleXMLElement $taxes, SimpleXMLElement $tax, array $attributesToUpdate = array(), array $attributesToRemove = array()) { $newTax = new SimpleXMLElement('<tax/>'); $taxRulesGroups = $taxes->xpath('//taxRulesGroup[1]'); $insertBefore = $taxRulesGroups[0]; if (!$insertBefore) { die("Could not find any `taxRulesGroup`, don't know where to append the tax.\n"); } /** * Add the `tax` node before the first `taxRulesGroup`. * Yes, the dom API is beautiful. */ $dom = dom_import_simplexml($taxes); $new = $dom->insertBefore($dom->ownerDocument->importNode(dom_import_simplexml($newTax)), dom_import_simplexml($insertBefore)); $newTax = simplexml_import_dom($new); $newAttributes = array(); foreach ($tax->attributes() as $attribute) { $name = $attribute->getName(); // This attribute seems to cause trouble, skip it. if ($name === 'account_number' || in_array($name, $attributesToRemove)) { continue; } $value = (string) $attribute; $newAttributes[$name] = $value; } $newAttributes = array_merge($newAttributes, $attributesToUpdate); foreach ($newAttributes as $name => $value) { $newTax->addAttribute($name, $value); } return $newTax; }
public function testMiddleChild() { $root = new SXE('<root><child1 /><child2 /><child3 /></root>'); $child3 = $root->child2->nextSibling(); $this->assertTrue($child3 instanceof SXE); $this->assertSame(dom_import_simplexml($root->child3), dom_import_simplexml($child3)); }
function toGeoJSON() { $rssDoc = new SimpleXMLElement($this->doc); $rssDoc->registerXPathNamespace('xls', 'http://www.opengis.net/xls'); $rssDoc->registerXPathNamespace('gml', 'http://www.opengis.net/gml'); $rssDoc->registerXPathNamespace('georss', 'http://www.georss.org/georss'); #for ingrid - portalu georss $rssDoc->registerXPathNamespace('ingrid', 'http://www.portalu.de/opensearch/extension/1.0'); // build feature collection $featureCollection = new FeatureCollection(); // elements of rss document $rssItems = $rssDoc->xpath("//item"); if (count($rssItems) > 0) { foreach ($rssItems as $item) { $rssItem_dom = dom_import_simplexml($item); $feature = new geoRSSItem(); $feature->targetEPSG = $this->targetEPSG; $feature->parse($rssItem_dom, $this->importItems); if (isset($feature->geometry) && $feature->geometry !== false) { $featureCollection->addFeature($feature); } } return $featureCollection->toGeoJSON(); } else { return "{'errorMessage':'Kein Ergebnis'}"; } }
function wp_nav_menu_extended($args = array()) { $_echo = array_key_exists('echo', $args) ? $args['echo'] : true; $args['echo'] = false; $menu = wp_nav_menu($args); // Load menu as xml $menu = simplexml_load_string($menu); // Find current menu item with xpath selector if (array_key_exists('xpath', $args)) { $xpath = $args['xpath']; } else { $xpath = '//li[contains(@class, "current-menu-item") or contains(@class, "current_page_item")]'; } $current = $menu->xpath($xpath); // If current item exists if (!empty($current)) { $text_node = (string) $current[0]->children(); // Remove link unset($current[0]->a); // Create required element with text from link $element_name = $args['replace_a_by'] ? $args['replace_a_by'] : 'span'; $dom = dom_import_simplexml($current[0]); $n = $dom->insertBefore($dom->ownerDocument->createElement($element_name, $text_node), $dom->firstChild); $current[0] = simplexml_import_dom($n); } $xml_doc = new DOMDocument('1.0', 'utf-8'); $menu_x = $xml_doc->importNode(dom_import_simplexml($menu), true); $xml_doc->appendChild($menu_x); $menu = $xml_doc->saveXML($xml_doc->documentElement); if ($_echo) { echo $menu; } else { return $menu; } }
/** * Return all rewrites * * @return array */ protected function loadRewrites() { $prototype = $this->_rewriteTypes; $return = array_combine($prototype, array_fill(0, count($prototype), array())); // Load config of each module because modules can overwrite config each other. Global config is already merged $modules = \Mage::getConfig()->getNode('modules')->children(); foreach ($modules as $moduleName => $moduleData) { // Check only active modules if (!$moduleData->is('active')) { continue; } // Load config of module $configXmlFile = \Mage::getConfig()->getModuleDir('etc', $moduleName) . DIRECTORY_SEPARATOR . 'config.xml'; if (!is_readable($configXmlFile)) { continue; } $xml = \simplexml_load_file($configXmlFile); if (!$xml) { continue; } $rewriteElements = $xml->xpath('//*/*/rewrite'); foreach ($rewriteElements as $element) { $type = dom_import_simplexml($element)->parentNode->parentNode->nodeName; if (!isset($return[$type])) { continue; } foreach ($element->children() as $child) { $groupClassName = dom_import_simplexml($element)->parentNode->nodeName; $modelName = $child->getName(); $return[$type][$groupClassName . '/' . $modelName][] = (string) $child; } } } return $return; }
function extract_vals($td_children) { global $val, $key, $results, $line_broken; for ($i = 0; $i < $td_children->length; $i++) { $item = $td_children->item($i); switch ($item->nodeType) { case XML_TEXT_NODE: if (!$line_broken) { $val .= $item->textContent; } break; case XML_ELEMENT_NODE: switch (strtolower($item->tagName)) { case 'b': push_val($item); break; case 'a': if (!$line_broken) { $val .= $item->textContent; } break; case 'br': $line_broken = true; break; case 'table': if (!count($results)) { @extract_vals(dom_import_simplexml(simplexml_import_dom($item)->tr[0]->td[0])->childNodes); } break 3; case 'hr': break 3; } } } }
public function testGrandchild() { $root = new SimpleDOM('<root><child1><grandchild /></child1><child2 /><child3 /></root>'); $grandchild = $root->child1->firstChild(); $this->assertTrue($grandchild instanceof SimpleDOM); $this->assertSame(dom_import_simplexml($root->child1->grandchild), dom_import_simplexml($grandchild)); }
public function testTextNode() { $root = new SXE('<root><child /></root>'); $return = $root->appendXML('my text node'); $this->assertXmlStringEqualsXmlString('<root><child />my text node</root>', $root->asXML()); $this->assertSame(dom_import_simplexml($root), dom_import_simplexml($return)); }
public function addCData($str) { $node = dom_import_simplexml($this); $no = $node->ownerDocument; $node->appendChild($no->createCDATASection($str)); return $this; }
function appendChildForSimpleXML($parent, $child) { $parentNode = dom_import_simplexml($parent); $childXml = dom_import_simplexml($child); $childNode = $parentNode->ownerDocument->importNode($childXml, true); return simplexml_import_dom($parentNode->appendChild($childNode)); }
public function generate($categories, $offers) { if (file_exists($this->tmpFile)) { if (filectime($this->tmpFile) + $this->fileLifeTime < time()) { unlink($this->tmpFile); $this->writeHead(); } } else { $this->writeHead(); } try { if (!empty($categories)) { $this->writeCategories($categories); unset($categories); } if (!empty($offers)) { $this->writeOffers($offers); unset($offers); } $dom = dom_import_simplexml(simplexml_load_file($this->tmpFile))->ownerDocument; $dom->formatOutput = true; $formatted = $dom->saveXML(); unset($dom, $this->xml); file_put_contents($this->tmpFile, $formatted); rename($this->tmpFile, $this->file); } catch (Exception $e) { unlink($this->tmpFile); } }
/** * Add CDATA to simpleXML node * * @param SimpleXMLElement $node * @param string $value * @return void */ protected function _addCDATA($node, $value) { $value = mb_convert_encoding($value, 'UTF-8', 'auto'); $domNode = dom_import_simplexml($node); $domDoc = $domNode->ownerDocument; $domNode->appendChild($domDoc->createCDATASection($value)); }
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); } }
/** * Return all rewrites * * @return array */ protected function loadRewrites() { $return = array('blocks', 'models', 'helpers'); // Load config of each module because modules can overwrite config each other. Globl config is already merged $modules = Mage::getConfig()->getNode('modules')->children(); foreach ($modules as $moduleName => $moduleData) { // Check only active modules if (!$moduleData->is('active')) { continue; } // Load config of module $configXmlFile = Mage::getConfig()->getModuleDir('etc', $moduleName) . DIRECTORY_SEPARATOR . 'config.xml'; if (!file_exists($configXmlFile)) { continue; } $xml = simplexml_load_file($configXmlFile); if ($xml) { $rewriteElements = $xml->xpath('//rewrite'); foreach ($rewriteElements as $element) { foreach ($element->children() as $child) { $type = simplexml_import_dom(dom_import_simplexml($element)->parentNode->parentNode)->getName(); if (!in_array($type, $this->_rewriteTypes)) { continue; } $groupClassName = simplexml_import_dom(dom_import_simplexml($element)->parentNode)->getName(); if (!isset($return[$type][$groupClassName . '/' . $child->getName()])) { $return[$type][$groupClassName . '/' . $child->getName()] = array(); } $return[$type][$groupClassName . '/' . $child->getName()][] = (string) $child; } } } } return $return; }
function handle() { $this->DCIRoot = new SimpleXMLElement("<DataRecord></DataRecord>"); $this->DCIDom = dom_import_simplexml($this->DCIRoot); $this->citation_handler = new citations($this->get_resource()); $CI =& get_instance(); $ds = $CI->ds->getByID($this->ro->data_source_id); $exportable = false; $lower_type = strtolower($this->ro->type); $allowedType = array('collection', 'repository', 'dataset'); if ($this->ro->hasTag('excludeDCI')) { return ""; } if ($this->overrideExportable || $ds->export_dci == DB_TRUE || $ds->export_dci == 1 || $ds->export_dci == 't') { $exportable = true; } $sourceUrl = $this->citation_handler->getSourceUrl(); if ($sourceUrl == null || !$exportable && !in_array($lower_type, $allowedType)) { return ""; } $this->getHeader(); $this->getBibliographicData($sourceUrl); $this->getAbstract(); $this->getRightsAndLicencing(); $this->getParentDataRef(); $this->getDescriptorsData(); $this->getFundingInfo(); $this->getCitationList(); return $this->DCIDom->ownerDocument->saveXML($this->DCIDom->ownerDocument->documentElement, LIBXML_NOXMLDECL); }