Mailinglisten-Archive |
Enrico Weigelt wrote:
> Deshalb ist es mir auch wichtig, daß die jeweiligen Strukturelemente
> eines Artikels möglichst sauber und einfach modelliert sind und im
> Fließtext sogut wie keine HTML-Tags (abgesehen von ein paar einfachen
> wie STRONG oder CITE) verwendet werden.
in diesem Fall ergibt sich das "mixed-content-Problem", das auch die
Entwickler von SimpleXML (PHP5) beschäftigt hat.
Dank an Björn Schotte für den Link:
http://www.zend.com/php5/articles/php5-simplexml.php
<zitat>
While SimpleXML is a great tool for processing XML, its simplicity does
come with a few drawbacks. Most notable among these is that processing
mixed XML and text content with SimpleXML is very hard. For example,
consider the following XML
<?xml version="1.0"?>
<flaw>
<blurb>
This <italic>is</italic> some sample <bold>text</bold> where
SimpleXML <underline>will</underline> not behave well.
</blurb>
</flaw>
Accessing $document->blurb would return an element iterator that
contained the contents of italic, bold, and underline. It would not,
however, return the text surrounding those elements. This is because
when given the choice between mixed elements and contents, SimpleXML
will always choose to return the elements, and ignore the contents, of a
particular tag.
SimpleXML has two solutions to this problem built into the library.
Firstly, a method called asXML() is provided, which will take the given
node and serialize its contents, as well as the contents of all its
children(), to either a file or a string. With the example above, you
would call $document->blurb->asXML() and it would return the full
contents of the blurb node in a format suitable for printing or further
processing.[...]
</zitat>
Wenn Du also mit SimpleXML arbeitest, sollte es kein Problem sein, den
gesamten "Mixed content" als String einzulesen.
Meiner Klasse fehlt diese Möglichkeit zur Zeit noch. Möglich ist nur,
den kompletten Inhalt eines Elements auszutauschen. Ich denke also, dass
die nächste Version von XML-line das kann.
Eventuell baue ich auch die Möglichkeit ein, dass man bestimmte Elemente
einfach ingnoriert, d.h. als String betrachtet.
Technisch am saubersten ist aber wohl die CDATA-Lösung.
Viele Grüße
Peter
--
http://www.media-palette.de/tools/xml-line/
php::bar PHP Wiki - Listenarchive