Jump to content

Recommended Posts

XML Parsing Error: junk after document element

Location: http://localhost:8080/php/script.php?file=test

Rule Number 6, column 1:

 

<?php

session_start();

define("CONST1", 5);
define("CONST2", 10);
define("CONSTERROR", false);
define("REFRESH_TIME", 2);

if(isset($_SESSION['views'])){
$_SESSION['views']=$_SESSION['views']+1;
}else{
$_SESSION['views']=1;
}

if(!isset($_SESSION['decision'])){
$_SESSION['decision'] = rand(1, CONST2);
}

function respond_xml($status, $message)
{
    $out = new XMLWriter();
    $out->openURI("php://output");
    $out->setIndent(true);

    $out->startDocument("1.0", "ISO-8859-1");
    $out->startElement("statuscheck");
    $out->writeElement("status", $status);
    $out->writeElement("message", $message);
    $out->endElement();
    $out->endDocument();
    $out->flush();
}

function main()
{
    header("Refresh: " . REFRESH_TIME . "; URL=http://localhost:8080/php/script.php?file=test");
    header("Content-type: text/xml");

    if (!isset($_GET["file"]))
        respond_xml("ERROR", "File parameter missing");

    while($_SESSION['views'] < CONST1){
        respond_xml("NOT OK", "File does not exist. ");
    }

    if($_SESSION['views'] >= CONST1 && CONSTERROR == true){
        respond_xml("ERROR", "Some error has occured!");
    }
    else{
        if($decision == 1){
            respond_xml("OK", "File exists. Decision: " . $_SESSION['decision']);
        }
        else{
            respond_xml("NOT OK", "File does not exist. Decision: " . $_SESSION['decision']);
        }
    }

}

main();

?>

Link to comment
https://forums.phpfreaks.com/topic/235064-xml-error/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.