簡體   English   中英

Grails渲染XML丟失xml格式和標簽

[英]Grails render XML lose xml format and tags

我請求Google Places API,並希望以XML格式獲得響應。 我這樣做:

def http = new HttpURLClient( )
def resp = http.request(url:uRL)
render(text: resp.getData(), encoding:"UTF-8", contentType:"text/xml")

它返回數據,但沒有XML標簽。 因此,普通數據作為字符串。 我100%確定,我會從Google獲得XML格式的數據。 Google的響應如下所示(顯示了瀏覽器):

<PlaceSearchResponse>
<status>OK</status>
<result>
<name>Beth-El Synagogue</name>
<vicinity>Elizabeth Av & Downing, St. John's</vicinity>
<type>synagogue</type>
<type>place_of_worship</type>
<type>establishment</type>
<geometry>
<location>
<lat>47.5799640</lat>
<lng>-52.7172920</lng>
</location>
</geometry>
<icon>
http://maps.gstatic.com/mapfiles/place_api/icons/worship_jewish-71.png
</icon>
<reference>
CnRwAAAAH3oJJ3PaJPk5kesLiioompBTCh2NUBDxAh-wUKwZkFeolqoDCOEoOTYe9UpUdhVhkqMoL9mPPd-C0PuIvkyqBwfvdli1zHvaaEfJklQBHd-haHfMceF4vlPxV5r9kaSyWTwOAGSJWQhT6pkXmmoMCBIQbP457ZvQWJsX0JIEc-DnORoU_NRRZIlZN08azb3UL_X-xpqS6N4
</reference>
<id>b61e059f04e643fce7f4750a42c686901096bab3</id>
</result>
<html_attribution>
Listings by <a href="http://www.yellowpages.ca/">YellowPages.ca</a>
</html_attribution>
</PlaceSearchResponse>

我只想再次渲染響應。 那么,頂部的代碼有什么問題呢? 謝謝。

首先將XML解析為文本:

import groovy.xml.XmlUtil
....
def http = new HttpURLClient( )
def resp = http.request(url:uRL)
def xmlAsText = XmlUtil.serialize(resp.data)
render(text: xmlAsText, encoding:"UTF-8", contentType:"text/xml")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM