XML/Transformer
| From: | Sebastian Bergmann | Date: | Sat, 06 Apr 2002 15:23:45 +0000 |
| Subject: | XML/Transformer | ||
| Groups: | php.pear.dev | ||
| Request: | Send a blank email to pear-dev+get-5216@lists.php.net to get a copy of this message | ||
'lo,
after some time working on it, Kristian and I decided today to import
our Transformer class into the PEAR CVS.
Documentation will be written soon, promised.
Here are some basic examples that hopefully show what you can do with
it:
<?php
require_once 'XML/Transformer.php';
$t = new Transformer(
array(
'overloadedElements' => array(
'h1' => array('start' => 'startElementH1',
'end' => 'endElementH1'
)
)
)
);
function startElementH1($attributes) {
return '<h2' .
Transformer::attributesToString($attributes) .
'>';
}
function endElementH1($cdata) {
return $cdata . '</h2>';
}
?>
<h1 align="center">text</h1>
Output: <h2 align="center">text</h2>
<?php
require_once 'XML/Transformer.php';
class Foo {
function startElement($element, $attributes) {
switch ($element) {
case 'bold': {
return '<b>';
}
break;
// ...
}
}
function endElement($element, $cdata) {
switch ($element) {
case 'bold': {
return $cdata . '</b>';
}
break;
// ...
}
}
}
$t = new Transformer(
array(
'startup' => false
)
);
$t->overloadNamespace(
'foo',
new Foo
);
$t->start();
?>
<foo:bold>text</foo:bold>
Output: <b>text</b>
Greetings,
Sebastian
--
Sebastian Bergmann
http://sebastian-bergmann.de/ http://phpOpenTracker.de/
Did I help you? Consider a gift: http://wishlist.sebastian-bergmann.de/