Convert DOMElement to string and then strip unwanted tags
Now, thanks to community, one problem was fixed ( Delete all elements of a certain type from an XML doc using PHP ). Now I luckily hit other :)
So, I have XML file:
<piletilve_info>
<shows>
<show>
<description>
<lat>
<![CDATA[
LA CENERENTOLA <BR><BR>
("Cinderella")<BR><BR>
Opera buffo by Gioachino Rossini<BR><BR>
Music Director and Conductor: Arvo Volmer<BR>
Stage Director and Set Designer: Michiel Dijkema (Amsterdam)<BR>
Costumes: Claudia Damm (Berlin)<BR><BR>
Premiere on November 10, 2006<BR>
Approx running time: 3 h 20 min<BR>
Sung in Italian with subtitles in Estonian and English<BR><BR>
Who hasn’t heard the fairy-tale of Cinderella who crouched in the ashes, danced to the tune of her step-sisters but finally found the man of her dreams and a happy life. Why should this fairy-tale be told today?<BR>
An exciting and unexpected solution of the story of Cinderella with striking scenery and fantastic-modern costumes is presented by the Dutch stage director Michiel Dijkema and the German designer Claudia Damm.<BR>
In this story, an unhappy soul dreams of a prince on a white horse and of a better life, and women following the last trends chase the prince, and a man who considers himself very wise, is only interested in himself.<BR>
"Cinderella" is not just a fairy-tale, it includes reality as well as dreams, a lot of fantasies, comedy and grotesque. And all of this is expressed by the brilliant and virtuous music of Rossini!<BR>
]]>
</lat>
</description>
</show>
</shows>
<other node>
...
</other node>
</piletilve_info>
I navigate to my needed node using this code:
$books = $xpath->query('shows/show/description');
foreach($books as $description)
{
$description->removeChild($eng_lang);
$lat_lang = $description->getElementsByTagName('lat')->item(0);
}
I want to output modified $lat_lang
elements , which is <[[CDATA ]]>
parent, content using this mixed function:
$lat_lang->nodeValue = mb_convert_encoding(print_r(strip_tags_only($lat_lang->item(0)->nodeValue, TRUE),'<html><head><body>'), 'UTF-8' ,$encoding);
, but I fail and when I execute script on apache server, I get this error:
The XML page cannot be displayed Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.
Only one top level element is allowed in an XML document. Error processing resource 'http://www.bilesuserviss.lv/lv_filtrs_...
Catchable fatal error: Object of class DOMElement could not be converted to string in /var/www/...
Could you help me finding solution?
Maybe the fact I do d开发者_StackOverflowevelop on delphi makes me this whole PHP<->XML coding more difficult that for normal people would .. :(
It was spelling problem. Function name was strip_only_tags(), but I called it with strip_tags_only();
I am working on delphi and php<>xml project whole day .. Kinda feel tired already :( Sorry all.
Also thansk to Gordon for commept. Kinda woke me up :D
精彩评论