私は現在、libxml2での c-binding を使用して、crystal-lang の c14n サポートを追加しようとしています。xmlC14NDocSave を使用して、正規の xml をファイルに保存することに成功しました。私が抱えている問題は、xmlC14NDocSaveTo と xmlC14NExecute の両方の xmlOutputBufferPtr にあります。
私が受け取るエラーは(MacおよびLinux)です
xmlC14NExecute: 出力バッファ エンコーダー != NULL ですが、C14N には UTF8 出力が必要です
ドキュメントの状態
C14N は UTF-8 出力を必要とするため、このバッファはエンコーダ==NULL を持たなければなりません (MUST)。
私はsrc/C14N/lib_C14N.cr
次のコードを持っています
type CharEncodingHandler = Void*
type Buff = Void*
#type OutputBuffer = Void*
struct OutputBuffer
context : Void*
writecallback : OutputWriteCallback
closecallback : OutputCloseCallback
encoder : CharEncodingHandler
buffer : Buff
conv : Buff
written : Int32
error : Int32
end
....
fun xmlC14NDocSaveTo(doc : LibXML::Node*, nodes : LibXML::NodeSet*, mode : Mode, inclusive_ns_prefixes : UInt8**, with_comments : Int32, buf : OutputBuffer*) : Int32
fun xmlC14NExecute(doc : LibXML::Node*, is_visible_callback : IsVisibleCallback, user_data : Void*, mode : Mode, inclusive_ns_prefixes : UInt8**, with_comments : Int32, buf : OutputBuffer*) : Int32
のsrc/C14N.cr
output = XML::LibC14N::OutputBuffer.new
p output.encoder
XML::LibC14N.xmlC14NDocSaveTo(@xml, nil, @mode, nil, 0, out output)
p ouput.encoder の結果はPointer(Void).null
、値が null のようです。
関数は、c14n.c
buf->encoder 構造体で null をチェックしているだけです
if (buf->encoder != NULL) {
xmlGenericError(xmlGenericErrorContext,
"xmlC14NExecute: output buffer encoder != NULL but C14N requires UTF8 output\n");
return (-1);
}
コードは私のgithubアカウントにあります。クローンして実行crystal spec