哪些 PHP 代码可以帮助我解析 xml 形式的 html 数据?
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
我正在尝试将整个电子邮件发送给 Mechanical Turk,并且我正在使用 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> ';
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> ';
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
HTML 不是 XML 的一种形式;不要尝试这样解析它。最好的选择是使用 HTML5 解析器,或者如果无法获得该解析器,则使用 SGML 解析器。
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.
xml 文档中的 html 代码可以通过多种方式嵌入:
htmlspecialchars()
将其转义,并部分
不同的 xml 解析器可能支持或不支持第三种方法,我会选择第一种或第二种。
html code inside an xml document may be embedded in a number of ways:
htmlspecialchars()
and send it<![CDATA[ ... ]]>
sectiondifferent xml parsers may support or not the third method, I'd go with the first or the second one.