哪些 PHP 代码可以帮助我解析 xml 形式的 html 数据?

发布于 2024-09-19 18:54:03 字数 897 浏览 1 评论 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

我正在尝试将整个电子邮件发送给 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

巨坚强 2024-09-26 18:54:03

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.

蓝眸 2024-09-26 18:54:03

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

  1. 使用 htmlspecialchars() 将其转义,并
  2. 使用 部分
  3. 将其转换为 XHTML,在 xmlns 属性中指定正确的名称空间,

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

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文