Error on line 2 at column 1: Extra content at the end of the document

前端 未结 4 1624
隐瞒了意图╮
隐瞒了意图╮ 2020-12-10 11:03

When I use the below code and parse the xml locally it works fine but when upload the same script at the server it shows error.

Note: I retrieved the $lng

相关标签:
4条回答
  • 2020-12-10 11:14

    I think you are creating a document that looks like this:

    <mycatch>
        ....
    </mycatch>
    <mycatch>
        ....
    </mycatch>
    

    This is not a valid XML document as it has more than one root element. You must have a single top-level element, as in

    <mydocument>      
      <mycatch>
          ....
      </mycatch>
      <mycatch>
          ....
      </mycatch>
      ....
    </mydocument>
    
    0 讨论(0)
  • 2020-12-10 11:17

    On each loop of the result set, you're appending a new root element to the document, creating an XML document like this:

    <?xml version="1.0"?>
    <mycatch>...</mycatch>
    <mycatch>...</mycatch>
    ...
    

    An XML document can only have one root element, which is why the error is stating there is "extra content". Create a single root element and add all the mycatch elements to that:

    $root = $dom->createElement("root");
    $dom->appendChild($root);
    // ...
    while ($row = @mysql_fetch_assoc($result)){
      $node = $dom->createElement("mycatch");
      $root->appendChild($node);
    
    0 讨论(0)
  • 2020-12-10 11:23

    The problem is database connection string, one of your MySQL database connection function parameter is not correct ,so there is an error message in the browser output, Just right click output webpage and view html source code you will see error line followed by correct XML output data(file). I had same problem and the above solution worked perfectly.

    0 讨论(0)
  • 2020-12-10 11:31

    You might have output (maybe error/debug output) that precedes your call to

    header("Content-type: text/xml");
    

    Therefore, the content being delivered to the browser is not "xml"... that's what the error message is trying to tell you (at least that was the case for me and I had the same error message as you've described).

    0 讨论(0)
提交回复
热议问题