使用iPhone将更多项目添加到xml文件 [英] Add more items to xml file using iphone
问题描述
有人帮助我,我正在使用一个xmlfile
Hi some body help me I am using one xmlfile like
<?xml version="1.0" encoding="UTF-8"?>
<MangoUserDataFile>
<Device>iPad</Device>
<Version>3.0</Version>
<UserName>XYZ</UserName>
<UserType>Admin</UserType>
<Module>TabView</Module>
<tab id="1">
<item>
<name>Admin</name>
<value>WebView</value>
<image>20</image>
</item>
</tab>
</MangoUserDataFile>
我想从iPad上在此xml文件中添加更多项目
I want to add more items in this xmlfile from IPad
例如,我正在创建一些名为:
For exmaple, I am creating some textfields called:
nametextfiled
, valuetextfiels
, imagetextfield
...,当我在这些文本字段中输入值并单击提交时,应在这些XML文件中创建另一个项目
... and once I enter the value in these textfields and click to submit at that time another items should be created in these XML File
有人可以给我任何有关如何从IPad向xmlfile添加另一个项目的想法吗.
Can some body give me any ideas on this how we add another item in xmlfile from IPad.
推荐答案
在这种情况下,您应该将所有元素重写到一个新的XML文件中,并尝试用新的XML文件替换旧的XML文件.
In that case you should rewrite all the elements into a new XML file, and try to replace the old XML file with the new one.
可以使用以下类进行书写:
Writing can be done using these classes:
//
// XMLBuilder.h
// TaxiSharing
//
// Created by Erle on 02.07.09.
// Copyright 2009 University of Duisburg-Essen,
// Institute of Computer Science and Business Computer Science
// Group for Pervasive Computing and User Interface Engineering
// All rights reserved.
//
#import <Foundation/Foundation.h>
@interface XMLBuilder : NSObject {
NSMutableString *XMLString;
}
@property(nonatomic,retain) NSMutableString *XMLString;
-(void)addTagToXML:(NSString *)tag withValue:(NSString *)value;
-(void)addSelfClosedTag:(NSString *)tag withInnerValueTitle:(NSString *)innerValueTitle andValue:(NSString *)value;
-(void)addSelfClosedTag:(NSString *)tag withInnerString:(NSString *)innerString;
-(void)addSingleTag:(NSString *)tag withInnerString:(NSString *)innerString;
-(void)addSingleValue:(NSString *)value;
-(void)addSingleTag:(NSString *)tag;
-(void)endSingleTag:(NSString *)tag;
-(void)closeXML;
@end
//
// XMLBuilder.m
// TaxiSharing
//
// Created by Erle on 02.07.09.
// Copyright 2009 University of Duisburg-Essen,
// Institute of Computer Science and Business Computer Science
// Group for Pervasive Computing and User Interface Engineering
// All rights reserved.
//
#import "XMLBuilder.h"
@implementation XMLBuilder
@synthesize XMLString;
-(id)init{
[super init];
XMLString = [[NSMutableString alloc] initWithFormat:@"<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"];
return self;
}
-(void)addTagToXML:(NSString *)tag withValue:(NSString *)value{
[XMLString appendFormat:@"<%@>%@</%@> \n",tag,value,tag];
}
-(void)addSelfClosedTag:(NSString *)tag withInnerValueTitle:(NSString *)innerValueTitle andValue:(NSString *)value{
[XMLString appendFormat:@"<%@ %@=%@ /> \n",tag,innerValueTitle,value];
}
-(void)addSelfClosedTag:(NSString *)tag withInnerString:(NSString *)innerString{
[XMLString appendFormat:@"<%@ %@ /> \n",tag,innerString];
}
-(void)addSingleTag:(NSString *)tag withInnerString:(NSString *)innerString{
[XMLString appendFormat:@"<%@ %@ > \n",tag,innerString];
}
-(void)addSingleValue:(NSString *)value{
[XMLString appendFormat:@"%@ \n",value];
}
-(void)addSingleTag:(NSString *)tag{
[XMLString appendFormat:@"<%@> \n",tag];
}
-(void)endSingleTag:(NSString *)tag{
[XMLString appendFormat:@"</%@> \n",tag];
}
-(void)closeXML{
[XMLString appendFormat:@"\n"];
}
-(void)dealloc{
[super dealloc];
[XMLString release];
}
@end
我在 http://www.iphonedevsdk.com/forum/tutorial-requests/34645-how-create-xml-file-dynamically.html .
这篇关于使用iPhone将更多项目添加到xml文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!