views:

57

answers:

3

I have a data of Element class. I'm trying to write its values to a file but I'm having trouble:

< 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? In addition, what is the best way for me to see (i.e. print out to screen) the available static variables and methods associated with an object? Thx.

More code snippets to help debug:

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
A: 

It sounds like you are trying to print the value of a input field element?

If so, then try:

out.write(field.getAttribute("value"));
Wade Tandy
Tried. It says `The method getAttribute(String) is undefined for the type Element`...
Zhang18
is the Element object you're using org.w3c.dom.Element?
Wade Tandy
Really have no idea. Just added some more code snippets for your reference.
Zhang18
A: 

Check out this one, for your second question: http://download.oracle.com/javase/1.4.2/docs/api/java/lang/Class.html

Hila's Master
+1  A: 

Turns out that this Bloomberg Prop data structure is long-winded 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...I don't think they try to make it easy! I'm also curious as to if there was a way that I could have figure this out by having Java print out the right method to use to trace down the data structure?

Zhang18