我必须解析外部提供的XML,该XML具有包含换行符的属性.使用SimpleXML,换行似乎丢失了.根据
another stackoverflow question,换行符应该对XML有效(尽管远远不够理想!).
他们为什么输了? [编辑]我怎样才能保存它们? [/编辑]
这是一个演示文件脚本(请注意,当换行符不在属性中时,它们会被保留).
带嵌入式XML的PHP文件
$xml = <<
First line of the row.
Followed by the second line.
Even a third!
XML;
$xml = new SimpleXMLElement( $xml );
print '
'; print_r($xml); print '';
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!
)
)