简体   繁体   English

将DOMElement转换为字符串,然后删除不需要的标记

[英]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 ). 现在,感谢社区,修复了一个问题( 使用PHP从XML文档中删除某种类型的所有元素 )。 Now I luckily hit other :) 现在我幸运地击中了其他:)

So, I have XML file: 所以,我有XML文件:

<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元素,它是<[[CDATA ]]>父级的内容:

$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: ,但是失败,并且在apache服务器上执行脚本时,出现以下错误:

The XML page cannot be displayed Cannot view XML input using XSL style sheet. 无法显示XML页面无法使用XSL样式表查看XML输入。 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. XML文档中仅允许一个顶级元素。 Error processing resource ' http://www.bilesuserviss.lv/lv_filtrs_ ... 处理资源' http://www.bilesuserviss.lv/lv_filtrs_时出错...

Catchable fatal error : Object of class DOMElement could not be converted to string in /var/www/... 可捕获的致命错误 :DOMElement类的对象无法在/ var / www /中转换为字符串。

Could you help me finding solution? 你能帮我找到解决方案吗?

Maybe the fact I do develop on delphi makes me this whole PHP<->XML coding more difficult that for normal people would .. :( 也许我确实在delphi上进行开发,这一事实使整个PHP <-> XML编码比普通人更加困难.. :(

It was spelling problem. 这是拼写问题。 Function name was strip_only_tags(), but I called it with strip_tags_only(); 函数名称为strip_only_tags(),但我使用strip_tags_only()对其进行了调用;

I am working on delphi and php<>xml project whole day .. Kinda feel tired already :( Sorry all. 我整天都在从事delphi和php <> xml项目的工作.. Kinda已经很累了:(对不起。

Also thansk to Gordon for commept. 也是为了纪念而向登高的唐斯克。 Kinda woke me up :D 金达叫醒我:D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM