Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
groovy XmlSlurper不解析我的xml文件_Xml_Grails_Groovy_Xmlslurper - Fatal编程技术网

groovy XmlSlurper不解析我的xml文件

groovy XmlSlurper不解析我的xml文件,xml,grails,groovy,xmlslurper,Xml,Grails,Groovy,Xmlslurper,我有一个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 regio

我有一个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>
我不知道哪里是我的错

我还尝试:result.genesummmary=eFetchResult./Entrezgene Set/.Entrezgene.Entrezgene\u summary

有人有主意吗?
谢谢

您不需要取消对顶部标记的引用(Entersgene Set>)。以下内容在groovyconsole中适用:

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 eFetchResult = new XmlSlurper().parseText(xml)
x = eFetchResult.Entrezgene.Entrezgene_summary
println "x is [${x}]"
xml=”“”
该基因编码的蛋白质是一种功能未知的血浆糖蛋白。该蛋白质与某些免疫球蛋白表基因家族成员蛋白质的可变区域显示出序列相似性。[由参考文献提供]
"""
def eFetchResult=new XmlSlurper().parseText(xml)
x=eFetchResult.Entrezgene.Entrezgene_摘要
println“x是[${x}]”
顺便说一句,您的错误消息是由于尝试使用带有破折号的属性名引起的

谢谢你, 我只是在你的帮助下解决了我的问题:

  • 通过使用引号,如果我的xml元素中有连字符(例如:result.test=eFetchResult.Entrezgene.“Entrezgene\u track-info.“Gene-track.”“Gene-track\u geneid”)
  • 通过删除,顶部标记引用(如果我保留顶部标记引用,我的映射值为空-很高兴知道:-)
这是我的解决方案:

  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.Entrezgene_summary
  }
  else{
    log.error("PubmedEfetchParserService.PubmedEsearch FAILED")
    log.error(url)
    log.error(connection.responseCode)
    log.error(connection.responseMessage)
  }
  render result
}
def publimedefetch={
def base=”http://eutils.ncbi.nlm.nih.gov/entrez/eutils/efetch.fcgi?"
def qs=[]

qs是的,你完全正确。只是澄清一下:
eFetchResult.Entrezgene Set.Entrezgene
被Groovy解释为
eFetchResult.Entrezgene-Set.Entrezgene
,因此错误消息(类集合没有这样的属性Entrezgene)但是,正如Jean指出的,根XML元素不必(实际上,可能不必)包含在GPath中。如果属性名中有破折号,通常的方法是单引号引用属性名,即:
eFetchResult.'Entrezgene-set'.Entrezgene
:-)
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 eFetchResult = new XmlSlurper().parseText(xml)
x = eFetchResult.Entrezgene.Entrezgene_summary
println "x is [${x}]"
  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.Entrezgene_summary
  }
  else{
    log.error("PubmedEfetchParserService.PubmedEsearch FAILED")
    log.error(url)
    log.error(connection.responseCode)
    log.error(connection.responseMessage)
  }
  render result
}