PHP SimpleXML doesn't preserve line breaks in XML attributes

前端 未结 6 1374
自闭症患者
自闭症患者 2020-12-11 04:31

I have to parse externally provided XML that has attributes with line breaks in them. Using SimpleXML, the line breaks seem to be lost. According to another stackoverflow

6条回答
  •  不知归路
    2020-12-11 04:52

    Well, this question is old but like me, someone might come to this page eventually. I had slightly different approach and I think the most elegant out of these mentioned.

    Inside the xml, you put some unique word which you will use for new line.

    Change xml to

    
    

    And then when you get path to desired node in SimpleXML in string output write something like this:

    $findme  = '\n';
    $pos = strpos($output, $findme);
    if($pos!=0)
    {
    $output = str_replace("\n","
    ",$output);

    It doesn't have to be '\n, it can be any unique char.

提交回复
热议问题