I'm trying to create a document with TouchXML. I followed up this tutorial https://github.com/TouchCode/TouchXML/blob/develop/Documentation/TouchXMLParsing.markdown to parse the XML, that's working fine. Now I try to generate the same XML for. I tried with
CXMLElement *piglet = [CXMLElement elementWithName:@"piglet" stringValue:@"1"];
CXMLElement *pigletList = [CXMLElement elementWithName:@"pigletlist"];
[pigletList addChild:piglet];
CXMLElement *name = [CXMLElement elementWithName:@"name" stringValue:@"Nifnif"];
[piglet addChild:name];
CXMLDocument *theDocument = [CXMLDocument documentWithRootElement:pigletList];
NSLog(@"document: %@", theDocument);
And the result is
<pigletlist>
<piglet>1<name>Nifnif</name></piglet>
</pigletlist>
So my question: How can I create a piglet like
<piglet id="1">
I tried with
CXMLElement *piglet = [CXMLElement elementWithName:[NSString stringWithFormat:@"piglet id=\"1\""]];
That worked fine, but not for a root element at the top, in my specific case I have an ID in my first XML-Element too and with [NSString stringWithFormat] it's placed in the closing tag too.
Thanks a lot, matz