私はこのようなXMLがあります。PHPのXMLのDOM - 更新XMLのDOM要素
<nitf:body.content>
<nitf:block>
<nitf:p style="@style1">Contents of paragraph1.</nitf:p>
<nitf:p style="@style2">Contents of paragraph2.</nitf:p>
<nitf:p style="@style1"><nitf:em class="@bold">This is bold</nitf:em> This is not bold</nitf:p>
<nitf:p style="@style1"><nitf:em class="@italic">This is italic</nitf:em> This is not italic</nitf:p>
</nitf:block>
</nitf:body.content>
をそして私はすべてのNITFのテキストを更新するためにループを作った次のように全角タグ:
foreach($this->doc->getElementsByTagNameNS($this->nitfNS, 'em') as $em) {
$class = $em->getAttribute('class');
if ($class == '@italic') {
$em->nodeValue = '<i>' . $em->nodeValue . '</i>';
}
elseif (strpos($class, 'bold') !== FALSE) {
$em->nodeValue = '<b>' . $em->nodeValue . '</b>';
}
$this->doc->saveXML($em);
}
ここで段落要素をもう一度ループすると、前のループで更新される段落はすべて空になります。
foreach ($this->doc->getElementsByTagNameNS($this->nitfNS, 'p') as $element) {
$textnode = $element->childNodes->item(0);
$txt = $textnode->wholeText; // this is EMPTY now
}私はどこかで読ん
"<>" の文字が台無しDOMパーサをするかもしれません。その場合、em要素を目的のhtmlタグ(イタリック&太字)で更新するにはどうすればよいですか。 ありがとうございます