ActiveResource を使用して、Redmine (バグ追跡ツール) が提供する REST Web サービスを使用しています。その Web サービスは、次のような XML を生成します。
<custom_field name="Issue Owner" id="15">Fred Fake</custom_field>
<custom_field name="Needs Printing" id="16">0</custom_field>
<custom_field name="Review Assignee" id="17">Fran Fraud</custom_field>
<custom_field name="Released On" id="20"></custom_field>
<custom_field name="Client Facing" id="21">0</custom_field>
<custom_field name="Type" id="22">Bug</custom_field>
<custom_field name="QA Assignee" id="23"></custom_field>
<custom_field name="Company Name" id="26"></custom_field>
<custom_field name="QA Notes" id="27"></custom_field>
<custom_field name="Failed QA Attempts" id="28">2</custom_field>
ただし、ActiveResource がそれを解析し、結果を繰り返し処理して出力すると、次のようになります。
Fred Fake
0
Fran Fraud
#<Redmine::Issue::CustomFields::CustomField:0x5704e95d>
0
Bug
#<Redmine::Issue::CustomFields::CustomField:0x32fd963>
#<Redmine::Issue::CustomFields::CustomField:0x3a68f437>
#<Redmine::Issue::CustomFields::CustomField:0x407964d6>
2
そうです、値を持つものからすべての属性情報を破棄しますが、空の要素からの属性情報は保持します。
言うまでもなく、id 15 (または何でも) の値を見つけようとしている場合、これは物事をかなり難しくします。位置によって物事を参照できるようになりましたが、これらの要素は将来変更される可能性が高いため、これは非常に脆弱です。ActiveResource に属性情報を保持させる方法が必要だと思いますが、特別なことは何もしていません。
(私の ActiveResource 拡張機能はわずか 5 行です。ActiveResource を拡張し、サービスの URL、ユーザー名、およびパスワードを定義するだけです)。
それで、ActiveResourceがこのXMLを奇妙に解析しないようにする方法を知っている人はいますか?