本文整理汇总了PHP中dom_import_simplexml函数的典型用法代码示例。如果您正苦于以下问题:PHP dom_import_simplexml函数的具体用法?PHP dom_import_simplexml怎么用?PHP dom_import_simplexml使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了dom_import_simplexml函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addProcessingInstruction
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;
}
示例2: addChild
/**
* 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;
}
示例3: render
/**
* 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;
}
示例4: prettyPrint
public static function prettyPrint($data, $rootNodeName = 'data')
{
$xml = self::_recursiveXmlEncode($data, $rootNodeName);
$dom = dom_import_simplexml($xml)->ownerDocument;
$dom->formatOutput = true;
return $dom->saveXML();
}
示例5: replaceChildNode
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);
}
示例6: saveAction
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('*/*/');
}
示例7: testLastChild
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));
}
示例8: addNodeToParent
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);
}
示例9: testGrandchild
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));
}
示例10: testIsChainable
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)));
}
示例11: analyzeSchematronIssues
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;
}
示例12: testGrandchild
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));
}
示例13: getQuestion
/** 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;
}
示例14: simpleXmlElementToDomDocument
/**
* 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;
}
示例15: addCData
public function addCData($nodename, $cdata_text)
{
$node = $this->addChild($nodename);
$node = dom_import_simplexml($node);
$no = $node->ownerDocument;
$node->appendChild($no->createCDATASection($cdata_text));
}