如何在 iPhone 中以 XML 格式读取 HTML [英] how to read HTML as XML in iphone
本文介绍了如何在 iPhone 中以 XML 格式读取 HTML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个自定义的 wordpress 帖子,查看源代码时看起来像这样.
i have a customised wordpress post that looks like this when view source.
如何将其解析为 XML 读取?
How can i read parse it as XML ?
<title>A sample quiz</title>
<content>Hello.</content>
<updatedDate>18/01/12</updatedDate>
<updatedTime>16:11</updatedTime>
<question>How many days are there in a week?</question>
<hint>No hint</hint>
<direction>Left</direction>
<answer1>4</answer1>
<answer2>5</answer2>
<answer3>6</answer3>
<answer4>7</answer4>
<correctAnswer>4</correctAnswer>
<score>20</score>
推荐答案
记得在你的 h 文件中设置.NSXMLParserDelegate并设置
remember to set in your h file. NSXMLParserDelegate and set
- (void)didload
{
NSString *site = [NSString stringWithFormat:@"http://www.mysite.it/mydirectory/myxml"];
NSURL *xmlURL = [NSURL URLWithString:site];
myParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[myParser setDelegate:self];
[myParser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
if ([elementName isEqualToString:@"title"]) {
NSLog(@"element %@",attributeDict);
//do something
}
else if ([elementName isEqualToString:@"content"]){
NSLog(@"element %@",attributeDict);
//do something
}
//ecc
}
这是非常简化的方法.了解更多详情http://www.xcode-tutorials.com/parsing-xml-files/一个>
this is very simplified method. for more detail http://www.xcode-tutorials.com/parsing-xml-files/
这篇关于如何在 iPhone 中以 XML 格式读取 HTML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文