gpt4 book ai didi

ios - 解析 XML - 捕获的字符串被前面截断。 swift

转载 作者:行者123 更新时间:2023-11-28 06:08:59 27 4
gpt4 key购买 nike

我对 xml 文档的解析工作正常,但我注意到某些标签(“AbstractText”)之间的文本随机被截断,我不知道是什么。同样,这只出现在这里和那里,并不总是这个标签的情况。我的解析代码如下,也是截断文本的示例。

 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.

最佳答案

这是正常行为。给定部分字符串,您必须将它们连接起来,最终结果由调用 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
}
}

关于ios - 解析 XML - 捕获的字符串被前面截断。 swift ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47266307/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com