Okay, so what I’m trying to do is create a java program that uses data obtained from a web service. I can get the data, but it’s in the format of an XML document, and when I print it to the (Eclipse) console, there are spaces between every letter and the replaceAll method doesn’t work. The relevant part of the code is below.
BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(webAdress).openStream()));
String XMLcode = reader.readLine();
XMLcode = XMLcode.concat(reader.readLine());
XMLcode = XMLcode.replaceAll(" ", "");
System.out.println(XMLcode); //in the finished program, I will do something with the data in the XML document.
The results look like this-
þÿ < ? x m l v e r s i o n = " 1 . 0 " e n c o d i n g = " U T F - 8 " ? >
followed by the actual data I’m looking for. Some internet searches implied that the þÿ meant that this was a text-encoding problem, but all methods I could find for converting UTF-8 into UTF-16 did not help (they do, however, change the þÿ into ??). Does anybody have any idea how to fix this, or know of a “standard” way to read XML that does not require it available in a file?
NOTE- I did not make the web service in question, and as such cannot modify it and don’t really know how it works.
Maybe is a good idea try with:
you can use the following code to test it:
just replace
new FileInputStream(infile)withnew URL(webAdress).openStream()