/** * Get Node * * @param Array $list * @param DOMDocument $doc * @return null */ private function getNode($list, $doc) { foreach ($list as $item) { $result = XmlUtil::selectSingleNode($doc->documentElement, $item); if ($result != null) { return $result; } } return null; }
<?php require "vendor/autoload.php"; $xml = \ByJG\Util\XmlUtil::createXmlDocumentFromStr('<root />'); $myNode = \ByJG\Util\XmlUtil::createChild($xml->documentElement, 'mynode'); \ByJG\Util\XmlUtil::createChild($myNode, 'subnode', 'text'); \ByJG\Util\XmlUtil::createChild($myNode, 'subnode', 'more text'); $otherNode = \ByJG\Util\XmlUtil::createChild($myNode, 'othersubnode', 'other text'); \ByJG\Util\XmlUtil::addAttribute($otherNode, 'attr', 'value'); echo $xml->saveXML(); print_r(\ByJG\Util\XmlUtil::xml2Array($xml)); $node = \ByJG\Util\XmlUtil::selectSingleNode($xml, '//subnode'); echo $node->nodeValue . "\n"; $node = \ByJG\Util\XmlUtil::selectSingleNode($myNode, '//subnode'); echo $node->nodeValue . "\n"; $nodeList = \ByJG\Util\XmlUtil::selectNodes($xml, '//subnode'); foreach ($nodeList as $node) { echo $node->nodeName; } echo "\n"; $nodeList = \ByJG\Util\XmlUtil::selectNodes($myNode, '//subnode'); foreach ($nodeList as $node) { echo $node->nodeName; } echo "\n"; \ByJG\Util\XmlUtil::addNamespaceToDocument($xml, 'my', 'http://www.example.com/mytest/'); echo $xml->saveXML() . "\n"; \ByJG\Util\XmlUtil::createChild($xml->documentElement, 'nodens', 'teste', 'http://www.example.com/mytest/'); \ByJG\Util\XmlUtil::createChild($xml->documentElement, 'my:othernodens', 'teste'); echo $xml->saveXML() . "\n"; $nodeList = \ByJG\Util\XmlUtil::selectNodes($xml, '//my:othernodens', ['my' => 'http://www.example.com/mytest/']);
/** *@desc Contains specific instructions to generate all XML informations-> This method is processed only one time-> Usually is the last method processed-> *@param DOMNode $current *@return void */ public function generateObject($current) { $objBoxButtons = XmlUtil::CreateChild($current, "buttons", ""); $clickEvent = ""; foreach ($this->_values as $button) { // InputButton $button if ($button->buttonType == ButtonType::CLICKEVENT) { $clickEvent .= ($clickEvent == "" ? "" : "|") . $button->name; } $nodeWorking = null; switch ($button->buttonType) { case ButtonType::CLICKEVENT: case ButtonType::SUBMIT: $nodeWorking = XmlUtil::CreateChild($objBoxButtons, "submit", ""); break; case ButtonType::RESET: $nodeWorking = XmlUtil::CreateChild($objBoxButtons, "reset", ""); break; case ButtonType::BUTTON: $nodeWorking = XmlUtil::CreateChild($objBoxButtons, "button", ""); XmlUtil::AddAttribute($nodeWorking, "onclick", $button->onClick); break; } XmlUtil::AddAttribute($nodeWorking, "caption", $button->caption); XmlUtil::AddAttribute($nodeWorking, "name", $button->name); } // Add Click Event $clickEventNode = XmlUtil::selectSingleNode($current, "clickevent"); if (is_null($clickEventNode)) { $clickEventNode = XmlUtil::CreateChild($current, "clickevent", $clickEvent); } else { $clickEventNode->nodeValue = $clickEventNode->nodeValue . "|" . $clickEvent; } }
/** *@desc Get a xml node element to return ajax component *@param IModule $module User module interface *@param string $element Element name *@return DOMDocument - Return the XHTML result */ public function getDocumentElement($module, $element = "", $id = "") { $px = $module->CreatePage(); if (is_null($px) || !$px instanceof PageXml) { return "<message>The return value of your CreatePage method is not a PageXml Class.</message>"; } if (empty($element)) { return XmlUtil::SaveXmlNodeToString($px->getRootNode()); } //\DOMNode $nodePage = $px->getRootNode(); if ($element == "") { $element = "blockcenter"; } $findedElements = XmlUtil::selectSingleNode($nodePage, $element); return XmlUtil::SaveXmlNodeToString($findedElements); }