Writing an Element object to a file using java

I have data of class Element. I am trying to write its values ​​to a file, but I am having problems:

< 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

Any suggestions on how I should handle this case? Also, what is the best way for me to see (e.g. print on the screen) the available static variables and methods associated with the object? thank.

Additional code snippets for debugging:

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
+3
source share
4 answers

It turns out that this Bloomberg Prop data structure is long to say the least:

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");

whew... , ! , , , Java ?

+5
 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              
   } 
  }

 }
+1

Looks like you're trying to print the value of an input field element?

If yes, try:

out.write(field.getAttribute("value"));
0
source

Source: https://habr.com/ru/post/1762746/


All Articles