XML 解析错误:Twilio 中文档元素之后的垃圾 [英] XML Parsing Error: junk after document element in Twilio

查看:20
本文介绍了XML 解析错误:Twilio 中文档元素之后的垃圾的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行以下代码,它向我显示了这个错误.有人能告诉我为什么我的 xml 有问题吗?当我在浏览器中运行它时,我得到:

I am running the following code, and it is showing me this error. Can someone tell me why is my xml giving a problem? When i run this in the browser I get:

XML Parsing Error: junk after document element

当我通过 Twiilio 运行此程序时,出现以下错误

When I run this through Twiilio I get the following error

parserMessage    Error on line 2 of document : Content is not allowed in prolog.

<?php

    header("content-type: text/xml");
      echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
    require "twilio-php-latest/Services/Twilio.php";

        /* Set our AccountSid and AuthToken */
    $AccountSid = "xxxxx";
    $AuthToken = "xxxx";

    include 'db.php';
    $caller=$_REQUEST['From'];
    /* Instantiate a new Twilio Rest Client */
    $client = new Services_Twilio($AccountSid, $AuthToken);

    $from= "+17864310795";
    $student_number=substr($caller,1);
        $db = new PDO("mysql:host=localhost;dbname=xxxx","xxxx","xxxx");
    $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    $studentData=getSingleStudentData($db,$student_number);
    foreach($studentData as $key=>$val)
    {
        $student_id=$val['student_id'];
        $phone=$val['phone_number'];
        $status=$val['status'];
        echo $student_id;
        // find out last call successfully completed by the student
        if($status==1)
        {
            $progress = getLastActivity($db,$student_id);
X
X
X
echo "done with initialize<br/>";
            $server= "http://sample.com";


        try {
            $to = '+' . $phone;            
            echo $phone;
            $questions_id_url='questions_id_0='.$questions_id[0].'&questions_id_1='.$questions_id[1].'&questions_id_2='.$questions_id[2];
            $questions_file_url='questions_file_0='.$questions_file[0].'&questions_file_1='.$questions_file[1].'&questions_file_2='.$questions_file[2];
            $url = $server.'/startCall.php?call_id='.$call_id.'&phone='.$phone.'&'.$questions_id_url.'&'.$questions_file_url.'&student_id='.$student_id.'&story='
            .$story.'&story_id='.$story_id.'&call_number='.$call_number.'&question_number=0&count_english=0&count_hindi=0&insert_receivecall=0';
            echo "here"."-----".$url;
            $client->account->calls->create(
            "+17864310795",
            $to,
            $url,
            array(
            'Method' => "GET",
            'FallbackMethod' => "GET",
            'StatusCallbackMethod' => "GET",
            'Record' => "false",
            ));
        } catch (Exception $e) {
            // log error
        }
        }
    }
?>
<Response>
     <Reject reason="busy"/>
</Response> 

我已经尝试了一切,希望我能发现错误

I have tried everything, and was hoping I could spot the error

推荐答案

Twilio 开发人员布道者在这里.

Twilio developer evangelist here.

我认为您的问题是您在该脚本中推出的不仅仅是 XML.您首先将内容类型设置为 XML 并 echoing XML 声明,但之后您开始 echo 看起来像调试命令的内容,它们不是有效的 XML,所以解析器会抛出一个错误.

I think your problem is that you're pushing out more than just XML within that script. You start by setting the content type to XML and echoing the XML declaration, but after that you start to echo what looks like debugging commands, which aren't valid XML, so the parser throws an error.

所以,首先,我会从脚本中注释掉或删除任何 echo 非 XML 内容的内容.

So, to start, I would comment out or remove anything that echos non XML content from your script.

如果这有帮助,请告诉我.

Let me know if that helps.

这篇关于XML 解析错误:Twilio 中文档元素之后的垃圾的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆