0
FalseAWS.MechanicalTurk.XMLParseErrorThere was an error parsing the XML question or answer data in your request. Please make sure the data is well-formed and validates against the appropriate schema. (1284779956270)Array00

我正在尝试将整个电子邮件发送给机械土耳其人,并且我正在使用 mtturk.lib.php 库来发送此邮件。我尝试了 urlencode 和 htmlentities 来尝试发送它,我确信有一个函数可以使此代码“格式化得足够好”以发送它。

$thequestion = '<a href="linkgoeshere" target="_blank">click here</a>';

$QuestionXML = '<QuestionForm xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd">
  <Question>
    <QuestionContent>
      <Text>'.$thequestion.'</Text>
    </QuestionContent>
    <AnswerSpecification>
      <FreeTextAnswer/>
    </AnswerSpecification>
  </Question>
</QuestionForm> ';
4

2 回答 2

2

HTML 不是 XML 的一种形式;不要试图这样解析它。您最好的选择是使用 HTML5 解析器,或者,如果无法获得,则使用 SGML 解析器。

于 2010-09-18T03:30:35.510 回答
0

xml 文档中的 html 代码可以通过多种方式嵌入:

  1. 用它来逃避它htmlspecialchars()并发送它
  2. <![CDATA[ ... ]]>用一个部分逃避它
  3. 将其转换为 XHTML,在 xmlns 属性中指定正确的命名空间

不同的 xml 解析器可能支持或不支持第三种方法,我会选择第一种或第二种方法。

于 2010-09-18T03:32:02.540 回答