So, I have HTML like this:
&l开发者_如何学编程t;blockquote>TEXT<br/>MORE TEXT<br/>SOME MORE TEXT</blockquote>
Basically, I need to get all of the text inbetween the blockquote tags, including the new-lines. Using "//blockquote" only returns the last line (SOME MORE TEXT) and using "//blockquote/text()" returns every line as a seperate item in the array.
Any help?
XPath:
//blockquote
will return all blockquote elements no matter where they are.
XPath:
//blockquote/text()
will return the child text nodes of all blockquote elements
XPath:
//blockquote//node()
will return any descendant node (text or tags) of all blockquote elements, that is, in your case:
TEXT<br/>MORE TEXT<br/>SOME MORE TEXT
Well your code is behaving properly. br is interpreted as another tag by the parser.
You will have to modify your code like this (I havent compiled this source code):
In your - (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
Create a NSMutableString *finalValue;
if([elementName isEqualtoString"@"br"])
{
finalValue = [NSString stringwithformat:@"%@\n",finalValue];
}
So basically you will have to append a \n to the parsed value when you encounter a br tag end.
精彩评论