0

質問形式でHTMLデータをPHPWebアプリケーションからMechanicalTurkに送信して、ユーザーが電子メールから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を送信することだけです-これまでのところこれほど困難であったことに驚いています。

これは、別のスレッドの続きの ようなものです-xml形式のhtmlデータを解析するのに役立つPHPコードは何ですか?

4

2 に答える 2

1

PHPでDOM/xmlを操作するためのDOMDocumentを見てください。XMLにHTMLを埋め込む場合は、次のようなCDATAセクションを使用します。

$QuestionXML = '<QuestionForm xmlns="http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd">
  <Question>
    <QuestionContent>
      <Text><![CDATA['.$thequestion.']]></Text>
    </QuestionContent>
    <AnswerSpecification>
      <FreeTextAnswer/>
    </AnswerSpecification>
  </Question>
</QuestionForm> ';
于 2010-09-18T07:43:40.280 に答える
0

あなたが何を求めているのか正確にはわかりません。これは、転送する必要がある XML を作成する方法です。質問を誤解していたら教えてください

また、.x​​sd ファイルによると必須の QuestionIdentifier ノードが欠落しているようです。

<?
$dom = new DOMDocument('1.0','UTF-8');
$dom->formatOutput = true;
$QuestionForm = $dom->createElement('QuestionForm');
$QuestionForm->setAttribute('xmlns','http://mechanicalturk.amazonaws.com/AWSMechanicalTurkDataSchemas/2005-10-01/QuestionForm.xsd');

// could loop this part for all the questions of the XML

$thequestion = '<a href="linkgoeshere" target="_blank">click here</a>';

//Not sure what this is supposed to be, but its required. Check the specs of the app for it. 
$questionID = "";

$Question = $dom->createElement('Question');

$QuestionIdentifier = $dom->createElement('QuestionIdentifier',$questionID);

$QuestionContent = $dom->createElement('QuestionContent');
$QuestionContent->appendChild($dom->createElement('Text',$thequestion));

$AnswerSpecification = $dom->createElement('AnswerSpecification');
$AnswerSpecification->appendChild($dom->createElement('FreeTextAnswer'));

$Question->appendChild($QuestionIdentifier);
$Question->appendChild($QuestionContent);
$Question->appendChild($AnswerSpecification);
$QuestionForm->appendChild($Question);
// End loop

$dom->appendChild($QuestionForm);

$xmlString = $dom->saveXML();

print($xmlString);
?>
于 2010-09-18T15:39:12.300 に答える