tags:

views:

40

answers:

2

Hi All,

I want to written a object holding data read from xml

    String data = null;
   while ((data = stdInput.readLine()) != null) {
               logger.info("Data:"+data);
    }

i want to return a obj holding the complete data read in while loop,how would i do that? its java

A: 

Google for "DOM XML parser" plus the name of your programming language. Maybe add "tutorial".

Aaron Digulla
+1  A: 

You can use a StringBuffer to combine all the lines, then output to a String when your loop is done:

String data = null;
StringBuffer dataBuffer = new StringBuffer();
while ((data = stdInput.readLine()) != null) {
    logger.info("Data:"+data);
    dataBuffer.append(data).append("\n");
}
String completeData = dataBuffer.toString();
Kaleb Brasee
You are _assuming_ Java.
Oded
This is not working out,data holds the complete xml in while loop logger.info("Data:"+data); will print the xml in console,i want the same data object to be returned outside while.
sarah
i am using java
sarah
@sarah, just return the completeData object, and comment out the logger call. The logger call is just to show you sausages being made.
bmargulies
its not working outthe while loop data will have the complete xml,when i am using thisdataBuffer.append(data).append("\n");}String completeData = dataBuffer.toString();and trying to pring completeData i wont get the xml itself
sarah
I got the output that isa the complete data,but the complete data should be only xml its appending some other data also likecurl -o xyz<?xml></xml>i need to read only from xml trimming curl -0 xyz data,how to do so?
sarah
Where do you get the input data from? I assumed it was from an XML file.
Kaleb Brasee