如何使用 PHP 将 DOM 序列化为 XML?
我正在尝试将 html 数据以问题形式从我的 php Web 应用程序发送到 Mechanical Turk,以便用户可以从电子邮件中查看整个 html 文档以供使用。到目前为止我遇到了困难。在下面链接的线程中,我尝试使用 html5-lib.php 解析 html 数据,但我认为我仍然缺少完成此操作的步骤。
这是我收到的当前错误:
Catchable fatal error: Object of class DOMNodeList could not be converted to string in urlgoeshere.php on line 35
这是我正在使用的当前代码...
$thequestion = '<a href="linkgoeshere" target="_blank">click here</a>';
$thequestion = HTML5_Parser::parseFragment($thequestion);
var_dump($thequestion);
echo $thequestion;
//htmlspecialchars($thequestion);
$QuestionXML = '<QuestionForm xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd">
<Question>
<QuestionContent>
<Text>'.$thequestion.'</Text> //<--- Line35
</QuestionContent>
<AnswerSpecification>
<FreeTextAnswer/>
</AnswerSpecification>
</Question>
</QuestionForm> ';
我不能 100% 确定解析器是否是我需要做的才能正确发送此错误 - 我想做的就是是通过这个 xml 类型文档发送 html - 我很惊讶到目前为止它是如此困难。
这在某种程度上是另一个线程的延续 - 哪些 PHP 代码可以帮助我解析 xml 形式的 html 数据?
I am attempting to send html data in a question form from my php web application to mechanical turk so a user can see the entire html document from an email to work with. I have had difficulty thus far. In the thread linked below, I attempted to parse the html data using html5-lib.php, but I think I'm still missing a step in order to complete this.
Here's the current error I'm receiving:
Catchable fatal error: Object of class DOMNodeList could not be converted to string in urlgoeshere.php on line 35
Here's the current code I'm working with...
$thequestion = '<a href="linkgoeshere" target="_blank">click here</a>';
$thequestion = HTML5_Parser::parseFragment($thequestion);
var_dump($thequestion);
echo $thequestion;
//htmlspecialchars($thequestion);
$QuestionXML = '<QuestionForm xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd">
<Question>
<QuestionContent>
<Text>'.$thequestion.'</Text> //<--- Line35
</QuestionContent>
<AnswerSpecification>
<FreeTextAnswer/>
</AnswerSpecification>
</Question>
</QuestionForm> ';
I'm not 100% sure if the parser is what I need to do in order to have this sent correctly - All I want to do is send html through this xml type document - I'm surprised it's been this difficult thus far.
This is somewhat of a continuation of another thread -
What PHP code will help me parse html data in an xml form?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 DOMDocument 以了解如何使用 DOM/ PHP 中的 XML。如果您想在 XML 中嵌入 HTML,请使用 CDATA 部分,如下所示:
Take a look at DOMDocument for working with DOM/xml in PHP. If you want to embed HTML in your XML, use CDATA sections like this:
不确定你到底在追求什么。这就是我创建需要传输的 XML 的方法。
如果我误解了这个问题,请告诉我
。您似乎还缺少 QuestionIdentifier 节点,根据 .xsd 文件,该节点是强制性的。
Not sure exactly what you're after. This is how i would create the XML needed to be transferred.
Please let me know if i misunderstood the question
It also seems that you are missing the QuestionIdentifier node which is mandatory according to the .xsd file.