1
我得到一個XML responde這樣的:Groovy中解析XML,並獲得價值
xml = grails.converters.XML.parse(new URL('http://...))
的XML如下:
<response>
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">272</int>
<lst name="params">
<str name="indent">on</str>
<str name="start">0</str>
<str name="q">roger federer</str>
<str name="version">2.2</str>
<str name="rows">10</str>
</lst>
</lst>
<result name="response" numFound="29327" start="0">
<doc>
<str name="id">135350</str>
<int name="revision">723055</int>
<date name="timestamp">2005-08-21T22:34:05Z</date>
<str name="title">Federer</str>
<str name="titleText">Federer</str>
<str name="user">Indech</str>
<str name="userId">3073</str>
</doc>
<doc>...</doc>
...
<doc>...</doc>
</result>
</response>
,我想在這裏保存三兩件事:
<int name="QTime">272</int>
<str name="q">roger federer</str>
<result name="response" numFound="29327" start="0">
我的輸出WUD是:
def one = '272'
def two = 'roger federer'
def three = '29327'
我該怎麼做到=?我將不勝感激這方面的一些幫助。優先考慮Groovy而不是Java。