質問

私は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>

ただテキストが必要か <Entrezgene_summary>

ここで私のコード:

  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 

んはっせいか

もう:結果です。geneSummary=eFetchResult./Entrezgeneト/.Entrezgene.Entrezgene_summary

誰かが考えたんですか?感謝

役に立ちましたか?

解決

あなたは、トップのタグ(Entersgene-セット>)を間接参照する必要はありません。 groovyコンソールでの私のために、次の作品ます:

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要素(例:結果です。試験=eFetchResult.Entrezgene.'Entrezgene_track-info'.'遺伝子トラック'.'遺伝子-track_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
}
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top