gpt4 book ai didi

iphone - 如何在 iPhone 中将 HTML 读取为 XML

转载 作者:行者123 更新时间:2023-11-29 04:49:28 25 4
gpt4 key购买 nike

我有一个自定义的 WordPress 帖子,在查看源代码时看起来像这样。

我如何将其解析为 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并设置

- (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/

关于iphone - 如何在 iPhone 中将 HTML 读取为 XML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9109032/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com