Конвертировать DOMElement в строку, а затем удалить ненужные теги - PullRequest
0 голосов
/ 14 ноября 2010

Теперь, благодаря сообществу, одна проблема была исправлена ​​( Удалите все элементы определенного типа из документа XML, используя 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 не может быть отображена Невозможно просмотреть ввод XML, используя стиль XSL простынь. Пожалуйста, исправьте ошибку и затем нажмите кнопку Обновить или попробуйте снова позже.


Разрешен только один элемент верхнего уровня в документе XML. Обработка ошибок ресурс «http://www.bilesuserviss.lv/lv_filtrs_...

Исправляемая фатальная ошибка : Объект класса DOMElement не может быть преобразован в строку в /var/www/...

Не могли бы вы помочь мне найти решение?

Возможно, тот факт, что я разрабатываю на Delphi, делает все это PHP <-> XML-кодирование более сложным, чем для обычных людей ..: (

1 Ответ

2 голосов
/ 14 ноября 2010

Это была проблема правописания.Имя функции было strip_only_tags (), но я вызвал его с помощью strip_tags_only ();

Я целый день работаю над проектом delphi и php <> xml.1004 * Также спасибо Гордону за комменд. Кинда разбудил меня: D

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...