/** * Funktion zum generieren von einem RSS 2.0 feed */ function generateRSS($ype = "html") { //Einf�gen des Basiswertes include_once "lib/XPath/XPath.class.php"; include_once "ext/blog/blog.class.php"; $xml = new XPath(); $xml->importFromString($this->prepareXML()); //Konfiguration einf�gen foreach ($this->config['rss'] as $key => $value) { if (!empty($value)) { $data = "\n<{$key}>{$value}</{$key}>\n"; $xml->appendChild("/rss[1]/channel[1]", $data); } } //So nun die letzten 10 Eintr�ge aus dem Blog einf�gen $blog = new weblog($this->blog); $entryArray = $blog->getLastXEntries(10); foreach ($entryArray as $entry) { $item = "\n<item>\n <title>" . $entry['attributes']['title'] . "</title>\n <link>http://www.grundprinzip.de/blog/single/" . $entry['number'] . ".html</link>\n <author>" . $entry['attributes']['mail'] . "</author>\n <category>" . $entry['attributes']['category'] . "</category>\n <description>" . $entry['teaser'] . "</description>\n </item>\n"; $xml->appendChild("/rss[1]/channel[1]", $item); } return $xml->exportAsXml(); }
$xmlOptions = array(XML_OPTION_CASE_FOLDING => TRUE, XML_OPTION_SKIP_WHITE => TRUE); $xPath = new XPath(FALSE, $xmlOptions); //$xPath->bDebugXmlParse = TRUE; if (!$xPath->importFromString($xmlSource)) { echo $xPath->getLastError(); exit; } _title("Following was imported:"); echo $xPath->exportAsHtml(); _title("Get some content"); echo "Last text part in <AAA>: '" . $xPath->wholeText('/AAA[1]', -1) . "'<br>\n"; echo "All the text in <AAA>: '" . $xPath->wholeText('/AAA[1]') . "'<br>\n"; echo "The attibute value in <BBB> using getAttributes('/AAA[1]/BBB[1]', 'FOO'): '" . $xPath->getAttributes('/AAA[1]', 'FOO') . "'<br>\n"; echo "The attibute value in <BBB> using getData('/AAA[1]/@FOO'): '" . $xPath->getData('/AAA[1]/@FOO') . "'<br>\n"; _title("Append some additional XML below /AAA/BBB:"); $xPath->appendChild('/AAA[1]/BBB[1]', '<CCC> Step 1. Append new node </CCC>', $afterText = FALSE); $xPath->appendChild('/AAA[1]/BBB[1]', '<CCC> Step 2. Append new node </CCC>', $afterText = TRUE); $xPath->appendChild('/AAA[1]/BBB[1]', '<CCC> Step 3. Append new node </CCC>', $afterText = TRUE); echo $xPath->exportAsHtml(); _title("Insert some additional XML below <AAA>:"); $xPath->reindexNodeTree(); $xPath->insertChild('/AAA[1]/BBB[1]', '<BB> Step 1. Insert new node </BB>', $shiftRight = TRUE, $afterText = TRUE); $xPath->insertChild('/AAA[1]/BBB[1]', '<BB> Step 2. Insert new node </BB>', $shiftRight = FALSE, $afterText = TRUE); $xPath->insertChild('/AAA[1]/BBB[1]', '<BB> Step 3. Insert new node </BB>', $shiftRight = FALSE, $afterText = FALSE); echo $xPath->exportAsHtml(); _title("Replace the last <BB> node with new XML data '<DDD> Replaced last BB </DDD>':"); $xPath->reindexNodeTree(); $xPath->replaceChild('/AAA[1]/BB[last()]', '<DDD> Replaced last BB </DDD>', $afterText = FALSE); echo $xPath->exportAsHtml(); _title("Replace second <BB> node with normal text"); $xPath->reindexNodeTree();