Crowdflower の場合、CMLLXML
を定義する必要があります。CML は XML に非常に似ているため、このタスクに使用したいと考えて
います。Crowdflower は、次のような CML タグを定義します。
<cml:textarea label="Sample text area:" />
また<cml:checkbox label="A single checkbox with a default value" />
(Crowdflower の Web サイトから引用: [ 1 ])
さらに、これらのCMLファイルは通常、ルート要素を使用しません。それを使用してCML要素を作成しようとするとlxml
、XMLSyntaxError
. Is there a switch to ignore undefined namespace prefixes in LXML?のソリューションを使用したいと思います。ですが、作成されたCMLにはルートがありません。
不明な名前空間プレフィックスを無視するように LXML を変更するにはどうすればよいですか?
コード
from lxml import etree
txt = "An example label"
txt_elm = etree.fromstring('<cml:text label="%s" />' % txt)
エラーメッセージ
txt_elm = etree.fromstring('<cml:text label="%s" />' % txt)
File "lxml.etree.pyx", line 2994, in lxml.etree.fromstring (src/lxml/lxml.etree.c:63296)
File "parser.pxi", line 1617, in lxml.etree._parseMemoryDocument (src/lxml/lxml.etree.c:93649)
File "parser.pxi", line 1495, in lxml.etree._parseDoc (src/lxml/lxml.etree.c:92453)
File "parser.pxi", line 1011, in lxml.etree._BaseParser._parseDoc (src/lxml/lxml.etree.c:89097)
File "parser.pxi", line 577, in lxml.etree._ParserContext._handleParseResultDoc (src/lxml/lxml.etree.c:84804)
File "parser.pxi", line 676, in lxml.etree._handleParseResult (src/lxml/lxml.etree.c:85904)
File "parser.pxi", line 616, in lxml.etree._raiseParseError (src/lxml/lxml.etree.c:85228)
lxml.etree.XMLSyntaxError: Namespace prefix cml on text is not defined, line 1, column 16
例 1
<h2>Image 1 :</h2>
<img src="{{urlmedia1}}" width="450" height="300">
<h2>Image 2 :</h2>
<img src="{{urlmedia2}}" width="450" height="300">
<cml:radios label="Which one of these two images conveys the most {{axis}} ?" validates="required">
<cml:radio label="Image 1"/>
<cml:radio label="Image 2"/>
</cml:radios>
例 2
<p>Focus on the emotion you feel when watching these shots. Which one convey? <b>{{axis}}</b> the most ?</p>
<p>While you have the right to watch the shots as many times as you want, you should focus on your first impression.</p>
<hr/>
<p>video 1: <em>{{miscdata1}}</em></p>
<object style="height: 300px; width: 490px">
<param name="movie" value="{{urlmedia1}}" />
<param name="allowFullScreen" value="true" />
<param name="allowScriptAccess" value="always" />
<embed src="{{urlmedia1}}" type="application/x-shockwave-flash" allowfullscreen="false" allowScriptAccess="always" width="490" height="300"/>
</object>
<hr/>
<p>video 2: <em>{{miscdata2}}</em></p>
<object style="height: 300px; width: 490px">
<param name="movie" value="{{urlmedia2}}" />
<param name="allowFullScreen" value="true" />
<param name="allowScriptAccess" value="always" />
<embed src="{{urlmedia2}}" type="application/x-shockwave-flash" allowfullscreen="false" allowScriptAccess="always" width="490" height="300"/>
</object>
<hr/>
<cml:radios label="Which one conveys {{axis}} the most?" validates="required">
<cml:radio label="Shot 1" />
<cml:radio label="Shot 2" />
</cml:radios>
両方の例は以下から引用されています: 2
注: 私の目標は CML 構造を構築することであり、解析することではありません。