3

Element クラスのデータがあります。その値をファイルに書き込もうとしていますが、問題があります:

< Some process to acquire values into the variable "fieldData" >

// Prepare file output
FileWriter fstream = new FileWriter("C:/output.txt");
BufferedWriter out = new BufferedWriter(fstream);

Element field = fieldData.getElement(i);

out.write(field);  // DOESN'T WORK: The method write(int) in the type BufferedWriter is not applicable for the arguments (Element)
out.write(field.getValueAsString()); // DOESN'T WORK: Cannot convert SEQUENCE to String

このケースをどのように処理すべきかについて何か提案はありますか? また、オブジェクトに関連付けられた使用可能な静的変数とメソッドを確認する (つまり、画面に出力する) 最良の方法は何ですか? どうも。

デバッグに役立つその他のコード スニペット:

private static final Name SECURITY_DATA = new Name("securityData");
private static final Name FIELD_DATA = new Name("fieldData");

Element securityDataArray = msg.getElement(SECURITY_DATA); // msg is a Bloomberg desktop API object
Element securityData = securityDataArray.getValueAsElement(0);
Element fieldData = securityData.getElement(FIELD_DATA);
Element field = fieldData.getElement(0)
out.write(field);  // DOESN'T WORK: The method write(int) in the type BufferedWriter is not applicable for the arguments (Element)
out.write(field.getValueAsString()); // DOESN'T WORK: Cannot convert SEQUENCE to String
4

4 に答える 4

5

このブルームバーグ プロップのデータ構造は、控えめに言っても長ったらしいことがわかります。

private static final Name SECURITY_DATA = new Name("securityData");
private static final Name FIELD_DATA = new Name("fieldData");

Element securityDataArray = msg.getElement(SECURITY_DATA); // msg is a Bloomberg desktop API object
Element securityData = securityDataArray.getValueAsElement(0);
Element fieldData = securityData.getElement(FIELD_DATA);
Element field = fieldData.getElement(0); 

/* the above codes were known at the time of the question */
/* below is what I was shown by a bloomberg representative */

Element bulkElement = field.getValueAsElement(0);
Element elem = bulkElement.getElement(0);
out.write(elem.name() + "\t" + elem.getValueAsString() + "\n");

ふぅ…簡単にしようとしているとは思えない!また、データ構造をトレースするために使用する正しいメソッドをJavaに出力させることで、これを理解できる方法があったかどうかについても興味がありますか?

于 2010-09-02T15:32:03.980 に答える
1
 Element element = msg.GetElement("securityData");
 for (int i = 0; i < element.NumValues; i++)
 {

  Element security = element.GetValueAsElement(i);  //ie: DJI INDEX
  Element fields = security.GetElement("fieldData");//ie: INDX_MEMBERS

  for (int j = 0; j < fields.NumElements; j++) 
  {
   Element field = fields.GetElement(j); //a list of members

   for (int k = 0; k < field.NumValues; k++)
   {
       //print field.GetValueAsElement(k); //print members name              
   } 
  }

 }
于 2012-11-28T05:30:15.020 に答える
0

2 番目の質問については、こちらをご覧ください: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Class.html

于 2010-09-01T21:26:17.020 に答える
0

入力フィールド要素の値を出力しようとしているようですね?

その場合は、次を試してください。

out.write(field.getAttribute("value"));
于 2010-09-01T21:20:49.110 に答える