开发者

What PHP code will help me parse html data in an xml form?

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

I'm trying to send entire emails to mechanical turk, and I am using the mtturk.lib.php library to send this. I tried urlencode and htmlentities to attempt to send it, I'm sure there's a function that will make this code "formatted well enough" to send it through.

$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&开发者_如何转开发gt;
      <FreeTextAnswer/>
    </AnswerSpecification>
  </Question>
</QuestionForm> ';


HTML is not a form of XML; don't try to parse it as such. Your best bet is to use a HTML5 parser, or, failing to obtain that, an SGML parser.


html code inside an xml document may be embedded in a number of ways:

  1. escape it all the hard way with htmlspecialchars() and send it
  2. escape it with a <![CDATA[ ... ]]> section
  3. convert it to XHTML, specify the right namespace in an xmlns attribute

different xml parsers may support or not the third method, I'd go with the first or the second one.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜