建材行业网站建设/软文范文200字
我已经使用教程中的xml解析器创建了一个应用程序。但本教程发现很容易。在此xml文件从本地xml解析。但如果我需要从解析xml文件的价值说我www.xxxxx.com/xxx.xml..how可以修改代码...指导,请..从此示例代码的服务器中的xml文件解析xml值
- (void) applicationDidFinishLaunching:(UIApplication *)application {
// find "sample.xml" in our bundle resources
NSString *sampleXML = [[NSBundle mainBundle] pathForResource:@"sample" ofType:@"xml"];
NSData *data = [NSData dataWithContentsOfFile:sampleXML];
// create a new SMXMLDocument with the contents of sample.xml
NSError *error;
SMXMLDocument *document = [SMXMLDocument documentWithData:data error:&error];
// check for errors
if (error) {
NSLog(@"Error while parsing the document: %@", error);
return;
}
// demonstrate -description of document/element classes
NSLog(@"Document:\n %@", document);
// Pull out the node
SMXMLElement *books = [document.root childNamed:@"books"];
// Look through children of type
for (SMXMLElement *book in [books childrenNamed:@"book"]) {
// demonstrate common cases of extracting XML data
NSString *isbn = [book attributeNamed:@"isbn"]; // XML attribute
NSString *title = [book valueWithPath:@"title"]; // child node value
float price = [[book valueWithPath:@"price"] floatValue]; // child node value (converted)
// show off some KVC magic
NSArray *authors = [[book childNamed:@"authors"].children valueForKey:@"value"];
NSLog(@"Found a book!\n ISBN: %@ \n Title: %@ \n Price: %f \n Authors: %@", isbn, title, price, authors);
}
}
我试过很多教程那么多小时,最后我从我的应用程序中使用这些代码得到了很好的结果。但我需要从服务器导入xml文件...
2012-07-04
Dany