问题
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