groovy XmlSlurper 无法解析我的 xml 文件
我有一个 xml,但无法使用 xmlslurper 解析该文件。 这里是我的 xml 文件的副本:
<Entrezgene-Set>
<Entrezgene>
<Entrezgene_summary>The protein encoded by this gene is a plasma glycoprotein of unknown function. The protein shows sequence similarity to the variable regions of some immunoglobulin supergene family member proteins. [provided by RefSeq]</Entrezgene_summary>
</Entrezgene>
</Entrezgene-Set>
我只需要从
获取文本
这里是我的代码:
def pubmedEfetch = {
def base = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?"
def qs = []
qs << "db=gene"
qs << "id=1"
qs << "retmode=xml"
def url = new URL(base + qs.join("&"))
def connection = url.openConnection()
def result = [:]
if(connection.responseCode == 200){
def xml = connection.content.text
def eFetchResult = new XmlSlurper().parseText(xml)
result.geneSummary = eFetchResult.Entrezgene-Set.Entrezgene.Entrezgene_summary
}
else{
log.error("PubmedEfetchParserService.PubmedEsearch FAILED")
log.error(url)
log.error(connection.responseCode)
log.error(connection.responseMessage)
}
render result
}
以及我的错误消息:
Error 500: groovy.lang.MissingPropertyException: No such property: Entrezgene for class: java.util.Set
Servlet: grails
URI: /geneInfo/grails/genes/pubmedEfetch.dispatch
Exception Message: No such property: Entrezgene for class: java.util.Set
Caused by: groovy.lang.MissingPropertyException: No such property: Entrezgene for class: java.util.Set
Class: GenesController
我不明白我的错在哪里?
我也尝试: result.geneSummary = eFetchResult./Entrezgene-Set/.Entrezgene.Entrezgene_summary
有人有想法吗? 谢谢
I have an xml, and I can't parse this file with xmlslurper.
Here a copy of my xml file :
<Entrezgene-Set>
<Entrezgene>
<Entrezgene_summary>The protein encoded by this gene is a plasma glycoprotein of unknown function. The protein shows sequence similarity to the variable regions of some immunoglobulin supergene family member proteins. [provided by RefSeq]</Entrezgene_summary>
</Entrezgene>
</Entrezgene-Set>
I just need to get text from <Entrezgene_summary>
Here my code :
def pubmedEfetch = {
def base = "http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?"
def qs = []
qs << "db=gene"
qs << "id=1"
qs << "retmode=xml"
def url = new URL(base + qs.join("&"))
def connection = url.openConnection()
def result = [:]
if(connection.responseCode == 200){
def xml = connection.content.text
def eFetchResult = new XmlSlurper().parseText(xml)
result.geneSummary = eFetchResult.Entrezgene-Set.Entrezgene.Entrezgene_summary
}
else{
log.error("PubmedEfetchParserService.PubmedEsearch FAILED")
log.error(url)
log.error(connection.responseCode)
log.error(connection.responseMessage)
}
render result
}
And my error message :
Error 500: groovy.lang.MissingPropertyException: No such property: Entrezgene for class: java.util.Set
Servlet: grails
URI: /geneInfo/grails/genes/pubmedEfetch.dispatch
Exception Message: No such property: Entrezgene for class: java.util.Set
Caused by: groovy.lang.MissingPropertyException: No such property: Entrezgene for class: java.util.Set
Class: GenesController
I don't see where is my fault?
I also try : result.geneSummary = eFetchResult./Entrezgene-Set/.Entrezgene.Entrezgene_summary
Someone has an idea?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您不需要取消引用顶部标签 (Entersgene-Set>)。以下内容在 groovyconsole 中适用于我:
顺便说一句,您的错误消息是由于尝试使用带有破折号的属性名称引起的。
You don't need to dereference the top tag (Entersgene-Set>). The following works for me in groovyconsole:
BTW, your error message is caused by trying to use a property name with a dash in it.
谢谢你,
我只是在您的帮助下解决我的问题:
这是我的修复:
Thank you,
I just fix my problem with your help :
Here my fix :