2017-11-13 5 views
1

XML文書の解析はうまくいきますが、特定のタグ(「AbstractText」)の間にあるテキストが無作為に切り捨てられ、何もわかりません。繰り返しますが、これはここだけしか現れず、必ずしもこのタグの場合ではありません。解析のための私のコードは下にあり、また切り詰められたテキストの例です。解析XML - 取得された文字列が先頭に切り捨てられます。 Swift

var abstractBool = false 
var abstract = "" 

func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) { 
     switch elementName { 
     case "AbstractText": 
      abstractBool = true 
     } 
} 


func parser(_ parser: XMLParser, foundCharacters string: String) { 
     if abstractBool{ 
      abstract = string 
     } 
} 


func parser(_ parser: XMLParser, didEndElement elementName: String, 
namespaceURI: String?, qualifiedName qName: String?) { 
     switch elementName { 
      case "AbstractText": 
      abstractBool = false 
     } 
} 
リモートサーバから

生のXML:

私は抽出することができるよ何
<Abstract> 
<AbstractText> 
Protein kinase C (PKC) has been shown to activate the mammalian target of 
rapamycin complex 1 (mTORC1) signaling pathway, a central hub in the 
regulation of cell metabolism, growth and proliferation. However, the 
mechanisms by which PKCs activate mTORC1 are still ambiguous. Our previous 
study revealed that activation of classical PKCs (cPKC) results in the 
perinuclear accumulation of cPKC and phospholipase D2 (PLD2) in recycling 
endosomes in a PLD2-dependent manner. Here, we report that mTORC1 activation 
by phorbol 12,13-myristate acetate (PMA) requires both classic, cPKC, and 
novel PKC (nPKC) isoforms, specifically PKCη, acting through distinct 
pathways. The translocation of mTOR to perinuclear lysosomes was detected 
after treatment of PKC activators, which was not colocalized with PKCα- or 
RAB11-positive endosomes and was not inhibited by PLD inhibitors. We found 
that PKCη inhibition by siRNA or bisindolylmaleimide I effectively decreased 
mTOR accumulation in lysosomes and its activity. Also, we identified that 
PKCη plays a role upstream of the v-ATPase/Ragulator/Rag pathway in response 
to PMA. These data provides a spatial aspect to the regulation of mTORC1 by 
sustained activation of PKC, requiring co-ordinated activation of two 
distinct elements, the perinuclear accumulation of cPKC- and PLD-containing 
endosomes and the nPKC-dependent translation of of mTOR in the perinuclear 
lysosomes. The close proximity of these two distinct compartments shown in 
this study suggests the possibility that transcompartment signaling may be a 
factor in the regulation of mTORC1 activity and also underscores the 
importance of PKCη as a potential therapeutic target of mTORC-related 
disorders. 
</AbstractText> 
</Abstract> 

文字列の次のフロント・エンド・切り捨てられた部分である:

scompartment signaling may be a factor in the regulation of mTORC1 activity 
and also underscores the importance of PKCη as a potential therapeutic target 
of mTORC-related disorders. 

答えて

1

正常な行動です。あなたは部分文字列が与えられており、それらを連結しなければならず、最後の結果は、didStartElementdidEndElementの間に経過時に得られたすべての文字列の連結によって与えられます。現在の要素を変数に保存してください。foundCharacters部分文字列の所在を知っています。

var abstractBool = false 
var abstract = "" 

func parser(_ parser: XMLParser, didStartElement elementName: String, namespaceURI: String?, qualifiedName qName: String?, attributes attributeDict: [String : String] = [:]) { 
     switch elementName { 
     case "AbstractText": 
      abstractBool = true 
      abstract = "" // if you read an XML document with multiple 
          // AbstractText elements, you need to reset 
          // the variable 
     } 
} 


func parser(_ parser: XMLParser, foundCharacters string: String) { 
    if abstractBool{ 
     abstract.append(string) 
    } 
} 


func parser(_ parser: XMLParser, didEndElement elementName: String, 
namespaceURI: String?, qualifiedName qName: String?) { 
    switch elementName { 
     case "AbstractText": 
     abstractBool = false 
     // Here the variable 'abstract' contains the full text 
    } 
} 
+0

あなたのPSはiOSには適用されません。macOSだけです。 – rmaddy

+0

コメントありがとうございます。質問に「iOS」というタグが付いているので、PSを削除しました。 –

関連する問題