ios - GDataXML string values are not saved into data on [GDataXML XMLData] -


i have gdataxmldocument created xml file.

xml being read file:

<pages count="1"> <page pagenumber="1"></page> </pages>

i need add new "page" tag (programmatically). xml after new "page" added:

<pages count="2"> <page pagenumber="1"></page> <page pagenumber="2"></page> </pages>

everything ok long there no need set stringvalue "page" tags;

xml should this:

<pages count="2"> <page pagenumber="1">some value</page> <page pagenumber="2">some other value</page> </pages>

and in program looks! (you can see xmlstring method), when save document ([document xmldata]) file looks this:

<pages count="2"> <page pagenumber="1">some value</page> <page pagenumber="2"></page> </pages>

page number 1 (the old one) has value, page number 2 (the new one) has not. why can change stringvalue on old tags, can't on new ones?

its work me,

gdataxmlelement *element = [gdataxmlelement elementwithname:@"pages" stringvalue:nil]; [element addattribute:[gdataxmlnode attributewithname:@"count" stringvalue:@"1"]];   gdataxmlelement *tempnode = [gdataxmlnode elementwithname:@"page" stringvalue:@"some value"]; [tempnode addattribute:[gdataxmlnode attributewithname:@"pagenumber" stringvalue:@"1"]];  [element addchild:tempnode];  tempnode = [gdataxmlnode elementwithname:@"page" stringvalue:@"some other value"]; [tempnode addattribute:[gdataxmlnode attributewithname:@"pagenumber" stringvalue:@"2"]];  [element addchild:tempnode];  [element attributeforname:@"count"].stringvalue = @"2";  gdataxmldocument *mydoc = [[gdataxmldocument alloc] initwithrootelement:element];  nsdata *data = [mydoc xmldata];  nsarray *dirpath = nssearchpathfordirectoriesindomains(nsdocumentdirectory, nsuserdomainmask, yes); nsstring *path = [dirpath objectatindex:0]; path = [path stringbyappendingstring:@"/myxml.xml"];  // log path file nslog(@"%@", path);  [data writetofile:path atomically:yes];  data = nil;  data = [nsdata datawithcontentsoffile: path];  mydoc = nil;  mydoc = [[gdataxmldocument alloc] initwithdata:data options:0 error:nil];  nslog(@"%@", [mydoc rootelement]); 

Comments

Popular posts from this blog

javascript - Count length of each class -

What design pattern is this code in Javascript? -

hadoop - Restrict secondarynamenode to be installed and run on any other node in the cluster -