Opa pessoal
Estou recorrendo a vcs, depois de perder o fim de semana tentando resolver isto (e sem encontrar nada para me dar uma luz).
Tenho a seguinte chamada para um webservice REST:
@GET
@Produces("application/xml")
public String getOodleList(@QueryParam("min") Double minValue, @QueryParam("max") Double maxValue, @PathParam("type") String listType, @PathParam("region") String region, @QueryParam("address") String addr) throws IOException, JAXBException{
try{
String addressParam = "" + addr;
RestResponse result = OodleListService.getOodleList(minValue, maxValue, listType, region, addressParam);
String saida = result.getDataAsString();
return saida;
} catch (IOException ex) {
Logger.getLogger(listResource.class.getName()).log(Level.SEVERE, null, ex);
}
return "";
}
Basicamente, estou usando uma String para gerar o XML, conforme segue método getOodleList:
public static RestResponse getOodleList(Double minValue, Double maxValue, String listType, String region, String address) throws IOException {
try{
String encoded = URLEncoder.encode(address, "UTF-8");
String addressParam = "" + encoded;
OodleList list = new OodleList(minValue, maxValue, listType, region, addressParam);
String xmlOut = " <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\" ?>\n";
xmlOut += "<list>\n";
int results = list.getNumResults();
for(int num = 0; num < results; num++){
xmlOut += "\t<element>\n";
xmlOut += "\t\t<name>" + list.getName(num) + "</name>\n";
xmlOut += "\t\t<description>" + list.getDescription(num) + "</description>\n";
xmlOut += "\t\t<url>" + list.getLink(num) + "</url>\n";
xmlOut += "\t\t<price>" + String.valueOf(list.getPrice(num)) + "</price>\n";
xmlOut += "\t\t<location>\n";
xmlOut += "\t\t\t<lat>" + String.valueOf(list.getLatitude(num)) + "</lat>\n";
xmlOut += "\t\t\t<lng>" + String.valueOf(list.getLongitude(num)) + "</lng>\n";
xmlOut += "\t\t</location>\n";
xmlOut += "\t\t<images>\n";
String[] imagesURL = list.getImages(num);
int numImages = imagesURL.length;
for(int i = 0; i < numImages; i++){
xmlOut += "\t\t\t<imgURL>" + imagesURL[i] + "</imgURL>\n";
}
xmlOut += "\t\t</images>\n";
xmlOut += "\t</element>\n";
}
xmlOut += "</list>";
return new RestResponse(xmlOut.getBytes());
}
catch(Exception e){
throw new IOException(e.getMessage());
}
}
A String parece gerar o XML no formato belezinha, conforme segue um exemplo de valor final de xmlOut:
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<list>
<element>
<name>Co-Op, Co-Op - Brooklyn, NY</name>
<description>Immaculate Studio, 1 bath unit on the 1st floor of pre-war building. Unit is fully renovated. Move in ready. New kitchen with stainless steel appliances, new bath, & new hardwood floors throughout. Sponsor Unit, no board approval required. As low as 10% down required. (Consult with bank). Maintenance is $374 a month. One Year Free Maintenance.</description>
<url>http://realestate.oodle.com/u_a2xx_/[telefone removido]-P1_2231p568,5-E152B7C0BF1E/realestate.oodle.com___bLMYos22Jb1kawkqbThWfsD0uw2YdD0gFMrPbWk9Rt8VeKVSTmwfAercP5mVwgGj7_Du4A4jjya8SC1BuxrvoZO0Zt2l8MuHQfH5AXaJ6KKvflrjHonEgg,,</url>
<price>95000.0</price>
<location>
<lat>40.619</lat>
<lng>-73.9227</lng>
</location>
<images>
<imgURL>http://i.oodleimg.com/item/2138744270u_1s?[telefone removido]</imgURL>
<imgURL>http://i.oodleimg.com/item/2138744270u_2s?[telefone removido]</imgURL>
<imgURL>http://i.oodleimg.com/item/2138744270u_3s?[telefone removido]</imgURL>
</images>
</element>
<element>
<name>Co-Op, Co-Op - Howard Beach, NY</name>
<description>Large L-Shaped Studio With Murphy Bed. 5th Floor Views, Eff. Kitchen Can Easily Be Coverted To A 1 Bedroom Unit. Close To Shopping, Schools And Transportation</description>
<url>http://realestate.brazil.oodle.com/u_a2xx_/[telefone removido]-P1_2231p568,5-E152B7C0BF1E/realestate.oodle.com___lRHlot9p3K9EOfyZ-dzQX5UnB5R6favoUXlGa-LFoys9bq4rO2rFSwnd_GDuISS1DkYVmsuQ05kUj4e6CnbhMNdP43UZwJiwhCQAquEBJv7YwKc_aYVlQymUJkcRCVfr332wCJZULaHjB0G6c2Vjig,,</url>
<price>79500.0</price>
<location>
<lat>40.6602</lat>
<lng>-73.8444</lng>
</location>
<images>
<imgURL>http://i.oodleimg.com/item/2092190704u_1s_condos,_townhouses_&_apts_for_sale_in_howard_beach_ny/?[telefone removido]</imgURL>
<imgURL>http://i.oodleimg.com/item/2092190704u_2s_condos,_townhouses_&_apts_for_sale_in_howard_beach_ny/?[telefone removido]</imgURL>
<imgURL>http://i.oodleimg.com/item/2092190704u_3s_condos,_townhouses_&_apts_for_sale_in_howard_beach_ny/?[telefone removido]</imgURL>
</images>
</element>
<element>
<name>Co-Op, Co-Op - Brooklyn, NY</name>
<description>Immaculate Studio, 1 bath unit on the 1st floor of pre-war building. Unit is fully renovated. Move in ready. New kitchen with stainless steel appliances, new bath, & new hardwood floors throughout. Sponsor Unit, no board approval required. As low as 10% down required. (Consult with bank). Maintenance is $374 a month. One Year Free Maintenance.</description>
<url>http://realestate.brazil.oodle.com/u_a2xx_/[telefone removido]-P1_2231p568,5-E152B7C0BF1E/realestate.oodle.com___7rMLN0BF2WFkawkqbThWfsD0uw2YdD0gFMrPbWk9Rt8VeKVSTmwfAercP5mVwgGj7_Du4A4jjya8SC1BuxrvoZO0Zt2l8MuHaJkvJteE1EhioaecU-z_JegXxb1xcTujIugF2-TlSfk,</url>
<price>95000.0</price>
<location>
<lat>40.619</lat>
<lng>-73.9227</lng>
</location>
<images>
<imgURL>http://i.oodleimg.com/item/2001379643u_1s?[telefone removido]</imgURL>
<imgURL>http://i.oodleimg.com/item/2001379643u_2s?[telefone removido]</imgURL>
<imgURL>http://i.oodleimg.com/item/2001379643u_3s?[telefone removido]</imgURL>
</images>
</element>
<element>
<name>Bridgeport 1BR 1BA</name>
<description> </description>
<url>http://realestate.brazil.oodle.com/r_a2xx_/[telefone removido]-720p569,745-E152B7C0BF1E/www.foreclosure.com___5np-G6jF9KyXixRds_dYVobUoJt89JZ1ln2e9zySiUzYjm9XozNd7LMpc5P3btC2iyiso88j9Klv3SHOwNOxEA,,</url>
<price>64000.0</price>
<location>
<lat>41.211</lat>
<lng>-73.2096</lng>
</location>
<images>
<imgURL>null</imgURL>
<imgURL>null</imgURL>
<imgURL>null</imgURL>
</images>
</element>
</list>
A página XML não pode ser exibida Não é possível exibir a entrada XML usando a folha de estilos XSL. Corrija o erro e clique no botão Atualizar ou tente novamente mais tarde.--------------------------------------------------------------------------------
Espaços em branco não são permitidos neste local. Erro ao processar o recurso 'http://localhost:8080/tcc/resources/list/sal...
Immaculate Studio, 1 bath unit on the 1st floor of pre-war building. Unit is fully renovated. Move in r...
Indo em "exibir código fonte" dessa página eu tenho o XML do jeito que deveria estar. Ou seja, a saída está ok, há algum problema na interpretação do documento.
Por favor, expliquem-me o que acontece. Não entendo este erro de espaços em branco não permitidos (e porque ocorre na tag "description" e não em "title"?)
E, se tem algo a ver com a XSL, como faço para edita-la ou fazer com que o Java gere-a corretamente para que fique compatível com o campo?
Desculpem, estou meio perdido nessa. :? :(