代码之家  ›  专栏  ›  技术社区  ›  HX_unbanned

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

  •  0
  • HX_unbanned  · 技术社区  · 14 年前

    现在,多亏了社区,一个问题解决了( Delete all elements of a certain type from an XML doc using PHP ). 现在我幸运地击中了另一个:)

    所以,我有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>
    

    我使用以下代码导航到所需的节点:

    $books = $xpath->query('shows/show/description');
            foreach($books as $description)
            {
                $description->removeChild($eng_lang);
                $lat_lang = $description->getElementsByTagName('lat')->item(0);
                }
    

    我想输出修改过的 $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);
    

    ,但我失败了,当我在apache服务器上执行脚本时,会出现以下错误:

    无法显示XML页 无法使用XSL样式查看XML输入 工作表。请更正错误并 然后单击“刷新”按钮,或尝试 稍后再来。


    只允许一个顶级元素 在XML文档中。错误处理 资源 ' http://www.bilesuserviss.lv/lv_filtrs_ ...

    可捕捉的致命错误 :对象 类DOMElement不能是 已转换为/var/www/…中的字符串。。。

    你能帮我找到解决办法吗?

    也许我在delphi上开发的事实使我编写整个PHP<->XML代码变得比普通人更困难。。:(

    1 回复  |  直到 7 年前
        1
  •  2
  •   HX_unbanned    14 年前

    是拼写问题。 函数名是strip_only_tags(),但我用strip_tags_only()调用它;

    我整天都在做delphi和php<gt;xml项目。。已经有点累了:( 对不起大家。

    同时也要向戈登汇报。有点把我吵醒了:D