/** * Read from file */ function load(&$ctx) { $dom = new DomDocument(); $dom->load($this->path); $dom->xinclude(); $this->xml = simplexml_import_dom($dom); }
/** * @param string $file * Path to input. * * @return SimpleXMLElement|bool */ public static function parse($file) { $dom = new DomDocument(); $dom->load($file); $dom->xinclude(); $xml = simplexml_import_dom($dom); return $xml; }
/** * Import custom-data from an XML file * * @param string $file * Path to an XML file. * @throws CRM_Core_Exception * @return void; */ public function run($file) { // read xml file $dom = new DomDocument(); if (!$dom->load($file)) { throw new CRM_Core_Exception("Failed to parse XML file \"{$file}\""); } $dom->xinclude(); $xml = simplexml_import_dom($dom); return $this->runXmlElement($xml); }
/** * Take the given $xml and turn it into a DomDocument and do the xincludes * * @param string $xml * @param string $xmlFilePath * * @return DomDocument */ private function generateXMLDom($xml, $xmlFilePath = null) { $dom = new DomDocument(); if (null !== $xmlFilePath) { $dom->documentURI = $xmlFilePath; } try { $dom->loadXML($xml); } catch (FrameEx $ex) { throw new FrameEx("Could not create DOM with xml\n\n: " . $xml); } $dom->xinclude(); return $dom; }
function retrieve($caseType) { $caseType = self::mungeCaseType($caseType); if (!CRM_Utils_Array::value($caseType, self::$_xml)) { if (!self::$_xml) { self::$_xml = array(); } // first check custom templates directory $fileName = NULL; $config = CRM_Core_Config::singleton(); if (isset($config->customTemplateDir) && $config->customTemplateDir) { // check if the file exists in the custom templates directory $fileName = implode(DIRECTORY_SEPARATOR, array($config->customTemplateDir, 'CRM', 'Case', 'xml', 'configuration', "{$caseType}.xml")); } if (!$fileName || !file_exists($fileName)) { // check if file exists locally $fileName = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'xml', 'configuration', "{$caseType}.xml")); if (!file_exists($fileName)) { // check if file exists locally $fileName = implode(DIRECTORY_SEPARATOR, array(dirname(__FILE__), 'xml', 'configuration.sample', "{$caseType}.xml")); } if (!file_exists($fileName)) { if (self::$_hookCache === NULL) { self::$_hookCache = array(); CRM_Utils_Hook::caseTypes(self::$_hookCache); } if (isset(self::$_hookCache[$caseType], self::$_hookCache[$caseType]['file'])) { $fileName = self::$_hookCache[$caseType]['file']; } } if (!file_exists($fileName)) { return FALSE; } } // read xml file $dom = new DomDocument(); $dom->load($fileName); $dom->xinclude(); self::$_xml[$caseType] = simplexml_import_dom($dom); } return self::$_xml[$caseType]; }
public function mocktest(&$caseTypes) { $paramsAct = array('option_group_id' => 2, 'version' => 3); $resultAct = civicrm_api3('activity_type', 'get', $paramsAct); if (in_array("Open Case", $resultAct['values'])) { $activityIdd = array_search('Open Case', $resultAct['values']); $paramsAct1 = array('option_group_id' => 2, 'version' => 3, 'id' => 18); $resultAct1 = civicrm_api3('option_value', 'delete', $paramsAct1); } $import = new CRM_Utils_Migrate_Import(); $path = __DIR__ . '/Hrdata.xml'; $dom = new DomDocument(); $dom->load($path); $dom->xinclude(); $xml = simplexml_import_dom($dom); $caseTypeName = $xml->name; $proc = new CRM_Case_XMLProcessor(); $caseTypesGroupId = civicrm_api3('OptionGroup', 'getvalue', array('name' => 'case_type', 'return' => 'id')); if (!is_numeric($caseTypesGroupId)) { throw new CRM_Core_Exception("Found invalid ID for OptionGroup (case_type)"); } // Create case type with 'Program Hiring Process' $paramsCaseType = array('option_group_id' => $caseTypesGroupId, 'version' => 3, 'name' => $caseTypeName, 'label' => $caseTypeName); $resultCaseType = civicrm_api3('option_value', 'create', $paramsCaseType); $this->casetype_id = $resultCaseType['values'][$resultCaseType['id']]['value']; $activitytype = $xml->ActivityTypes->ActivityType; foreach ($activitytype as $key => $val) { $activitytypename = (array) $val->name; $params = array('weight' => '2', 'label' => $activitytypename[0], 'name' => $activitytypename[0], 'filter' => 0, 'is_active' => 1, 'is_optgroup' => 1, 'is_default' => 0); $result = civicrm_api3('activity_type', 'create', $params); $this->activityIds[$result['values'][$result['id']]['name']] = $result['values'][$result['id']]['value']; //get id of open case activity type if ($activitytypename[0] == "Open Case") { $paramsAct = array('option_group_id' => 2, 'version' => 3); $resultAct = civicrm_api3('activity_type', 'get', $paramsAct); $this->opencase_activityId = array_search('Open Case', $resultAct['values']); } } }
/** * Try to process the Xinclude transformation * * @param string XML to process. * * @throws BuildException On errors */ protected function process($xml) { if ($this->basedir) { $cwd = getcwd(); chdir($this->basedir); } // Create and setup document. $xmlDom = new DomDocument(); $xmlDom->resolveExternals = $this->resolveExternals; $xmlDom->loadXML($xml); $xmlDom->xinclude(); if ($this->basedir) { chdir($cwd); } return $xmlDom->saveXML(); }
/** * @param string $caseType * @return SimpleXMLElement|FALSE */ public function retrieveFile($caseType) { $fileName = NULL; $fileXml = NULL; if (CRM_Case_BAO_CaseType::isValidName($caseType)) { // Search for a file based directly on the $caseType name $fileName = $this->findXmlFile($caseType); } // For backward compatibility, also search for double-munged file names // TODO In 4.6 or 5.0, remove support for loading double-munged file names if (!$fileName || !file_exists($fileName)) { $fileName = $this->findXmlFile(CRM_Case_XMLProcessor::mungeCaseType($caseType)); } if ($fileName && file_exists($fileName)) { // read xml file $dom = new DomDocument(); $dom->load($fileName); $dom->xinclude(); $fileXml = simplexml_import_dom($dom); } return $fileXml; }
function run() { // xml document $oXML = new DomDocument(); $oXML->load($this->_sXML); $oXML->xinclude(); // xslt document $oXSL = new DomDocument(); $oXSL->load($this->_sXSLT); // xslt processor $oProc = new XSLTProcessor(); $oProc->importStyleSheet($oXSL); // set all the parameters if (!is_null($this->_aParms)) { foreach ($this->_aParms as $k => $v) { $oProc->setParameter("", $k, $v); } } // make the transformation $sRst = $oProc->transformToXML($oXML); unset($oProc); unset($oXSL); unset($oXML); // if output is not null, save the result there if (!is_null($this->_sOutput)) { $fHand = @fopen($this->_sOutput, "w"); @fputs($fHand, $sRst); @fclose($fHand); } return $sRst; }
/** * Try to process the Xinclude transformation * * @param string XML to process. * * @throws BuildException On errors */ protected function process($xml) { if ($this->basedir) { $cwd = getcwd(); chdir($this->basedir); } $xmlDom = new DomDocument(); $xmlDom->loadXML($xml); $xmlDom->xinclude(); if ($this->basedir) { chdir($cwd); } return $xmlDom->saveXML(); }
<?php function loopElements($nodes) { $count = 0; foreach ($nodes as $node) { if ($node instanceof DOMElement) { $count++; if ($node->childNodes->length > 0) { $count += loopElements($node->childNodes); } } } return $count; } $xml = <<<DOC <?xml version="1.0" encoding="UTF-8"?> <root xmlns:xi="http://www.w3.org/2001/XInclude"> <a> <a_child1>ac1</a_child1> <a_child2>ac2</a_child2> </a> <b><xi:include xpointer="xpointer(/root/a)" /></b> <c><xi:include xpointer="xpointer(/root/b)" /></c> </root> DOC; $doc = new DomDocument(); $doc->loadXml($xml); $doc->xinclude(); $count = loopElements(array($doc->documentElement)); var_dump($count);