我用的版本是5.0,发现PHP在加载XML文件时,会自动把回车符替换成空格,请问这是怎么回事,该怎么规避?

解决方案 »

  1.   

    你是指标签内部的换行被替换了吗?
    应该不会的,除非你定义了DTD,loadXML的时候第二参数有设置吗?
    或者是你的其他代码替换了。能不能把你的XML字符串和代码贴出来看看
      

  2.   

    XML文件信息:
    <?xml version="1.0" encoding="UTF-8"?>
    <StatusInfo taskid="atpjfea3ol6">
    <sum>1</sum>
    <executed>1</executed>
    <passed>0</passed>
    <status>finished</status>
    <prevcase uri="atpjfe9lb1n" result="Failed"
    memo="[MAT Stack] ConnMobile fail when connect to mobile 8613907550004
    [MAT Stack] Mobile 8613907550004 hasn&apos;t connected yet.
    [消息检查]检查失败:(8613907550004)接口没有(mobile_msg)消息"
    trace=""
    caselogpath="d:\iCAT\Root\AutoSpace\System\CasesLog\atpjfea3ol6\atpjfe9lb1n\log.xml">
    <array type="arrayof_checkpoint"></array>
    </prevcase>
    <nextcase uri="" />
    </StatusInfo>
    $objDoc = new DOMDocument('1.0');
         if (!$objDoc->loadXML($executeState))
         {
         return array('ret' => -1);
         }
      

  3.   

    $objDoc = new DOMDocument();
    $ret = $objDoc->load('F:\ExecuteStateInfo.xml');
    $executeState = $objDoc->saveXML();
      

  4.   

    好像是自动转换的,为了XML处理提高效率,如果你保持的话建议在原XML中用\r\n代替直接换行,这样你在读出数据的时候可以保持换行的格式。