NSXMLParser Ignoring Text Between Certain Tags

旧城冷巷雨未停 提交于 2019-12-19 11:56:29

问题


I am trying to parse xml, but occasionally, if there is a child/sub tag within the tag which I am downloading with NSXMLParser, any text after that is ignored. Here is an example:

In the following block of XML I want the text to say:

and fill the caverns of that monstrous womb [NEW LINE] with arms and soldiery. In sight of Troy [NEW LINE] lies Tenedos, an island widely famed

The XML looks like:

<l n="tr">and fill the caverns of that monstrous womb</l>
<l n="tr">
with arms and soldiery.
<milestone ed="p" n="21" unit="card"/>
In sight of
<placeName key="perseus,Troy" authname="perseus,Troy">Troy</placeName>
</l>
<l n="tr">
lies
<placeName key="perseus,Tenedos" authname="perseus,Tenedos">Tenedos</placeName>
, an island widely famed
</l>

This only happens with the tag 'milestone', i.e to my knowledge the tag in between the ,'l' tag (the one that I am downloading) of 'placeName' is not a problem, and the text within 'l' and 'placename' download. It is that milestone tag. In the example above, the result ended up looking like:

and fill the caverns of that monstrous womb. [NEW LINE] Troy [NEW LINE] Tenedos, an island widely famed

As you can see, it is just that 'milestone' tag which is messing up the parsing. Here is my code to setup NSXMLParser:

- (void) parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
    [currentNodeContent appendString:string];
}

- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
    currentNodeContent = [[NSMutableString alloc] init];

If you have any further questions, or don't understand this question, please don't hesitate to ask. Thanks so much for the help in advance!

来源:https://stackoverflow.com/questions/20463277/nsxmlparser-ignoring-text-between-certain-tags

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!