Exemple #1
0
 /**
  * @access public
  * @return SingleRow
  * @throws IteratorException
  */
 public function moveNext()
 {
     if (!$this->hasNext()) {
         throw new IteratorException("No more records. Did you used hasNext() before moveNext()?");
     }
     $node = $this->_nodeList->item($this->_current++);
     $sr = new SingleRow();
     foreach ($this->_colNodes as $key => $colxpath) {
         $nodecol = XmlUtil::selectNodes($node, $colxpath, $this->_registerNS);
         if (is_null($nodecol)) {
             $sr->addField(strtolower($key), "");
         } else {
             foreach ($nodecol as $col) {
                 $sr->addField(strtolower($key), $col->nodeValue);
             }
         }
     }
     return $sr;
 }
Exemple #2
0
$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/']);
foreach ($nodeList as $node) {
    echo 'A' . $node->nodeName;
}
//$str = '<?xml version="1.0" encoding="utf-8"'
//    . '<root xmlns:my="http://www.example.com/mytest/">'
//    . '    '
//    . '</root>';
Exemple #3
0
 /**
  * @access public
  * @return DBIterator
  */
 public function getIterator()
 {
     $it = new XmlIterator(XmlUtil::selectNodes($this->_domDocument->documentElement, $this->_rowNode, $this->_registerNS), $this->_colNodes, $this->_registerNS);
     return $it;
 }
Exemple #4
0
 /**
  *@desc Transform an XMLDocument object with an XSLFile
  *@param DOMDocument $xml
  *@param XSLFilenameProcessor $xslFile XSL File
  *@return string - The transformation string
  */
 public function TransformDocument($xml, $xslFile)
 {
     // Add a custom XML based on attribute xmlobjet inside root
     // Example:
     // <page xmlobject="plugin.name(param1, param2)">
     $pattern = "/(?P<plugin>.*?)\\s*\\((?P<param>([#']?.*?[#']?\\s*,?\\s*)+)?\\)/";
     $xmlRoot = $xml->documentElement;
     $xmlRootAttributes = $xmlRoot->attributes;
     if ($xmlRootAttributes != null) {
         foreach ($xmlRootAttributes as $attr) {
             if ($attr->nodeName == "xmlobject") {
                 $match = preg_match_all($pattern, $attr->value, $matches);
                 for ($iCount = 0; $iCount < $match; $iCount++) {
                     $param = explode(",", $matches["param"][$iCount]);
                     for ($i = 0; $i <= 4; $i++) {
                         if (count($param) < $i + 1) {
                             $param[] = null;
                         } elseif ($param[$i] == "#CONTEXT#") {
                             $param[$i] = $this->_context;
                         } else {
                             $param[$i] = trim($param[$i]);
                         }
                     }
                     $className = str_replace('.', '\\', $matches["plugin"][$iCount]);
                     if ($className[0] != '\\') {
                         $className = "\\{$className}";
                     }
                     $plugin = new $className($param[0], $param[1], $param[2], $param[3], $param[4]);
                     if ($plugin instanceof IXmlnukeDocumentObject) {
                         $plugin->generateObject($xmlRoot);
                     } else {
                         $handler = new ObjectHandler($xmlRoot, $plugin);
                         $handler->CreateObjectFromModel();
                     }
                 }
             } else {
                 if ($attr->nodeName == 'xsl') {
                     $xslFile = new XSLFilenameProcessor($attr->value);
                 }
             }
         }
     }
     // Check if there is no XSL template
     if ($this->_outputResult != OutputData::Xslt) {
         if ($this->_extractNodes == "") {
             $outDocument = $xml;
         } else {
             $nodes = XmlUtil::selectNodes($xml->documentElement, "/" . $this->_extractNodes);
             $retDocument = XmlUtil::CreateXmlDocumentFromStr("<" . $this->_extractNodesRoot . "/>", false);
             $nodeRoot = $retDocument->documentElement;
             XmlUtil::AddAttribute($nodeRoot, "xpath", $this->_extractNodes);
             foreach ($nodes as $node) {
                 $nodeToAdd = XmlUtil::CreateChild($nodeRoot, $node->nodeName, "");
                 $attributes = $node->attributes;
                 foreach ($attributes as $value) {
                     XmlUtil::AddAttribute($nodeToAdd, $value->nodeName, $value->nodeValue);
                 }
                 XmlUtil::AddNodeFromNode($nodeToAdd, $node);
             }
             $outDocument = $retDocument;
         }
         if ($this->_outputResult == OutputData::Json) {
             return ObjectHandler::xml2json($outDocument, $this->_extraParams["json_function"]);
         } else {
             return $outDocument->saveXML();
         }
     }
     $this->_context->setXsl($xslFile->ToString());
     // Set up a transform object with the XSLT file
     //XslTransform xslTran = new XslTransform();
     $xslTran = new XSLTProcessor();
     $snippetProcessor = new SnippetProcessor($xslFile);
     //Uri
     try {
         $uri = $snippetProcessor->getUriFromXsl($xslFile, $this->_context);
     } catch (XMLNukeException $ex) {
         throw new EngineException("Cannot load XSL file. The following error occured: " . $ex->getMessage(), 751);
     }
     //Process smipets and put teh xsl StyleShet
     try {
         $xsl = $snippetProcessor->IncludeSnippet($uri);
     } catch (XMLNukeException $ex) {
         throw new EngineException("Cannot load XSL cache file. The following error occured: " . $ex->getMessage(), 752);
     }
     $xsl = FileUtil::fixUTF8($xsl);
     $xslDom = new DOMDocument();
     $xslDom->loadXML($xsl);
     $xslTran->importStyleSheet($xslDom);
     // Create Argument List
     $xslTran->setParameter("", "xml", $this->_context->getXml());
     $xslTran->setParameter("", "xsl", $this->_context->getXsl());
     $xslTran->setParameter("", "site", '_all');
     $xslTran->setParameter("", "lang", $this->_context->Language()->getName());
     $xslTran->setParameter("", "module", $this->_context->getModule());
     $xslTran->setParameter("", "transformdate", date("Y-m-d H:i:s"));
     $xslTran->setParameter("", "urlbase", $this->_context->get("xmlnuke.URLBASE"));
     $xslTran->setParameter("", "engine", "PHP");
     $xslTran->setParameter("", "url", $this->_context->getServerName(false, true) . $this->_context->get('REQUEST_URI'));
     //Transform and output
     $xtw = $xslTran->transformToXML($xml);
     $xhtml = new DOMDocument();
     $xhtml->loadXML($xtw);
     // Reload XHTML result to process PARAM and HREFs
     $paramProcessor = new ParamProcessor();
     $paramProcessor->AdjustToFullLink($xhtml, "A", "HREF");
     $paramProcessor->AdjustToFullLink($xhtml, "FORM", "ACTION");
     $paramProcessor->AdjustToFullLink($xhtml, "AREA", "HREF");
     $paramProcessor->AdjustToFullLink($xhtml, "LINK", "HREF");
     if ($this->_context->get("xmlnuke.ENABLEPARAMPROCESSOR")) {
         $paramProcessor->ProcessParameters($xhtml);
     }
     // ATENCAO: O codigo gerado pelo saveXML faz com que elementos vazios sejam
     //      comprimidos. Exemplo: <table />
     //      para o HTML isso eh ruim. Logo o metodo deve ser saveHTML que deixa o tag
     //      assim: <table></table>
     $arrCt = $this->_context->getSuggestedContentType();
     if ($arrCt["content-type"] == "text/html") {
         return FileUtil::fixUTF8(strtr($xhtml->saveHTML(), array("></br>" => "/>")));
     } else {
         return FileUtil::fixUTF8($xhtml->saveXML());
     }
 }