问题
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>
<FreeTextAnswer/>
</AnswerSpecification>
</Question>
</QuestionForm> ';
回答1:
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.
回答2:
html code inside an xml document may be embedded in a number of ways:
- escape it all the hard way with
htmlspecialchars()
and send it - escape it with a
<![CDATA[ ... ]]>
section - 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.
来源:https://stackoverflow.com/questions/3740257/what-php-code-will-help-me-parse-html-data-in-an-xml-form