开发者

Using Xpath to select blockquote text including <br/>

开发者 https://www.devze.com 2023-03-16 07:54 出处:网络
So, I have HTML like this: &l开发者_如何学编程t;blockquote>TEXT<br/>MORE TEXT<br/>SOME MORE TEXT</blockquote>

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号