gpt4 book ai didi

iphone - IOS中如何将xml文档转换成NSString

转载 作者:塔克拉玛干 更新时间:2023-11-02 10:10:44 25 4
gpt4 key购买 nike

我在 ios 中创建 xml,这是正确的(打印在日志上),但是当我将 xmlDocument 转换为 NSString 时,字符串在我打印时包含 null日志,sting 需要作为 webservice 的参数,如何将 xmlDocument 分配给 NSString ... 谢谢 ..

my code is ...

GDataXMLElement *rootElement = [GDataXMLElement elementWithName:@"Root"];

GDataXMLElement *zipCode = [GDataXMLElement elementWithName:@"zipCode" stringValue:self
.tfZipcode.text];
GDataXMLElement *phoneNo = [GDataXMLElement elementWithName:@"phoneNo" stringValue:self.tfPhone.text];
GDataXMLElement *cellNo = [GDataXMLElement elementWithName:@"cellNo" stringValue:self.tfCell.text];

GDataXMLElement *city = [GDataXMLElement elementWithName:@"city" stringValue:self.tfCity.text];
GDataXMLElement *zone = [GDataXMLElement elementWithName:@"zone" stringValue:self.tfZone.text];
GDataXMLElement *firstName = [GDataXMLElement elementWithName:@"firstName" stringValue:self.tfFirstName.text];
GDataXMLElement *lastName = [GDataXMLElement elementWithName:@"lastName" stringValue:self.tfLastName.text];
GDataXMLElement *address = [GDataXMLElement elementWithName:@"address" stringValue:self.tfAddress.text];
GDataXMLElement *email = [GDataXMLElement elementWithName:@"email" stringValue:self.tfEmail.text];

GDataXMLElement *service = [GDataXMLElement elementWithName:@"service" stringValue:self.tfService.text];
GDataXMLElement *product = [GDataXMLElement elementWithName:@"product" stringValue:self.tfProduct.text];
GDataXMLElement *symptom = [GDataXMLElement elementWithName:@"symptom" stringValue:self.tfSymptoms.text];
GDataXMLElement *jobType = [GDataXMLElement elementWithName:@"jobType" stringValue:self.tfJobType.text];
GDataXMLElement *ref = [GDataXMLElement elementWithName:@"ref" stringValue:self.tfRef.text];
GDataXMLElement *reqDate = [GDataXMLElement elementWithName:@"reqDate" stringValue:self.tfDateTime.text];


[rootElement addChild:zipCode];
[rootElement addChild:phoneNo];
[rootElement addChild:cellNo];
[rootElement addChild:city];
[rootElement addChild:zone];
[rootElement addChild:firstName];
[rootElement addChild:lastName];
[rootElement addChild:address];
[rootElement addChild:email];
[rootElement addChild:service];
[rootElement addChild:product];
[rootElement addChild:symptom];
[rootElement addChild:jobType];
[rootElement addChild:ref];
[rootElement addChild:reqDate];

GDataXMLDocument *xml = [[GDataXMLDocument alloc] initWithRootElement:rootElement];
NSLog(@"%@", [xml rootElement]); // print xml on log



NSString *stringXml = [xml rootElement];

NSLog(@"%@",stringXml);

最佳答案

试试这个,

NSString * YOURSTRING = [[NSString alloc] initWithData:[xml rootElement] encoding:NSUTF8StringEncoding];
NSLog(@"%@",YOURSTRING);

关于iphone - IOS中如何将xml文档转换成NSString,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15804214/

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