改行を含む属性を持つ外部から提供された XML を解析する必要があります。SimpleXML を使用すると、改行が失われたように見えます。別の stackoverflow questionによると、改行は XML に対して有効である必要があります (理想的とは言えませんが!)。
なぜ彼らは失われたのですか?[編集]どうすればそれらを保存できますか? [/編集]
デモ ファイルのスクリプトを次に示します (改行が属性に含まれていない場合、改行は維持されることに注意してください)。
XML が埋め込まれた PHP ファイル
$xml = <<<XML
<?xml version="1.0" encoding="utf-8"?>
<Rows>
<data Title='Data Title' Remarks='First line of the row.
Followed by the second line.
Even a third!' />
<data Title='Full Title' Remarks='None really'>First line of the row.
Followed by the second line.
Even a third!</data>
</Rows>
XML;
$xml = new SimpleXMLElement( $xml );
print '<pre>'; print_r($xml); print '</pre>';
print_r からの出力
SimpleXMLElement Object
(
[data] => Array
(
[0] => SimpleXMLElement Object
(
[@attributes] => Array
(
[Title] => Data Title
[Remarks] => First line of the row. Followed by the second line. Even a third!
)
)
[1] => First line of the row.
Followed by the second line.
Even a third!
)
)