File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes I/O and Streams and the fly likes Reading XML file as String is not working properly Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » I/O and Streams
Reply Bookmark "Reading XML file as String is not working properly" Watch "Reading XML file as String is not working properly" New topic
Author

Reading XML file as String is not working properly

Andrew Carney
Ranch Hand

Joined: Oct 17, 2006
Posts: 96
Hello

I am using the below code in order to read a file and convert it into a String.
When I read a text file it is fine however when i'm reading an xml file all I'm getting are the values of the XML attributes without any of the tags.
I'm assuming it has to be something with the encoding and was wondering if someone can help


Carey Brown
Ranch Hand

Joined: Nov 19, 2001
Posts: 130

Looks like it's eating your new-lines.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 11862
all I'm getting are the values of the XML attributes


Exactly how are you looking at the resulting String?

Bill

Java Resources at www.wbrogden.com
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 13842

Andrew Carney wrote:When I read a text file it is fine however when i'm reading an xml file all I'm getting are the values of the XML attributes without any of the tags.


Well, an XML file is a text file so that sounds wrong right away. However "getting the values of the attributes without any of the tags" can't possibly be done by the code you posted. So perhaps you could post the input and output of that code, so we can see what you mean by that statement?
Andrew Carney
Ranch Hand

Joined: Oct 17, 2006
Posts: 96
Hi,

I think I know what is causing me this problem although still don't know how to fix it.

I wanted to keep my question simple so probably should have mentioned that the file is going through an object of type org.springframework.web.multipart.MultipartFile first (I am doing this through a Spring MVC application).
It looks like that MultipartFile is being too smart and is stripping the xml tags from the file, leaving me with just the values. I have tried with a couple of coding options and I always get the same result - From a simple standalone java application I get the content of the file correctly however when reading it through a MultipartFile object it strips the tags out. I have posted this in the springsource forum and hopefully someone will be able to help there.
 
IntelliJ Java IDE
 
subject: Reading XML file as String is not working properly
 
Threads others viewed
BufferedReader .readLine() is not seeing end of file
Problem in csv file upload
how to read a file data into byte array
How to replace a line in a file
Read a Flat File line by line and add it to a StringBuffer
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture