0
votes

I'm trying to serialize a xml like this:

<Rows>
<RowOne SKATERID="706" MANUFACTURER="A-DZG" ISFACT="F" ISSKATE="F">True</RowOne>
<RowTwo SKATERID="318" MANUFACTURER="A-FGW" ISFACT="F" ISSKATE="T">True</RowTwo>
<RowThree SKATERID="458" MANUFACTURER="A-OPJ" ISFACT="F" ISSKATE="T">False</RowThree>
<RowFour SKATERID="178" MANUFACTURER="A-JSL" ISFACT="F" ISSKATE="T">True</RowFour>
</Rows>

But my question is what would be the best way of doing it including the atributes. So far I have my parser working and when I detect the node has attributes I'm sending those to a local nsmutabledictionay. but my question is how do I map the dictonary of attibutes and the value of the node. for example in RowOne the value is true bute it has the following attibutes SKATERID="706" MANUFACTURER="A-DZG" ISFACT="F" ISSKATE="F" .

in -(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{

I have this like of code:

if ([attributeDict count] != 0) {
    self.myDict = [[NSDictionary alloc] initWithDictionary:attributeDict];
}

in -(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{

I want to figure out what would be the best way of serializing the dictionary with the value of the node

I'll really appreciate your help

2
How about showing your current code and your desired result.Wain
I'd like it if HelenaM would give me my checkmark for her previous question where I gave her the solution to use didStartElement =PDan
The xcode, iphone, and ipad tags are not relevant to your question. That is why they are being removed.rmaddy

2 Answers

0
votes

EDIT: After re-reading your question, what do you mean by "serialize"? Pending your answer the solution below may not be what you desired.

If your XML attributes are static I would recommend creating a custom class, myRowClass, that operates like this...

myRow.SkaterID //NSString
myRow.Manufacturer //NSString
myRow.IsFact //BOOL
myRow.IsSkate //BOOL

With that custom class you can push each myRow object into your NSMutableDictionary like this...

[myDict setObject:myRow forKey:@"RowOne"]
myRow = nil;
myRowClass *myRow = [[myRowClass alloc]init];
<...Iterate through next XML Node...>
[myDict setObject:myRow forKey:@"RowTwo"]

Then when you need to access your data you can retrieve it like this...

NSString *myCurrentSkaterID = [[myDict objectForKey:@"RowTwo"].SkaterID]

or

myRowClass *myCurrentRow = [[myRowClass alloc]init];
myCurrentRow = [myDict objectForKey:@"RowTwo"];
NSString *myCurrentSkaterID = myCurrentRow.SkaterID;