转换对象的XML与的NSXMLParser
问题描述:
我有以下的Objective-C类定义:转换对象的XML与的NSXMLParser
//Book.h
#import <UIKit/UIKit.h>
@interface Book : NSObject {
NSInteger bookID;
NSString *title;
NSString *author;
NSString *summary;
}
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *author;
@property (nonatomic, retain) NSString *summary;
@end
//Book.m
#import "Book.h"
@implementation Book
@synthesize title, author, summary;
- (void) dealloc {
[summary release];
[author release];
[title release];
[super dealloc];
}
@end
现在,我想的变量(标题,作者,摘要)转换成XML的文件属性。该XML的文件应该是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<Book
title="Lord of the Rings"
author="J.R.R Tolkien"
summary="A long time ago" >
</Book>
我的第一种方式是写变量成的NSString的值,然后产生的NSData * XMLDATA,我充满了这些NSString的。但那真的只是让我工作。
有没有人一个更好的主意的Objective-C类转换成XML文件,或是否有任何XML解析器的Objective-C中,将实现该功能(还没有找到一个尚未)?
非常感谢
电贺