Reputation: 1632
So I am having an issue finding an undefined element in an element of an XML file.
I am able to parse to the element "item"...
<item key="ser.1.device.000001-3I67-2310.max_sampling_time" label="14459" sev="none" time="1373373210">14459</item>
Now if you notice, at the end of the "item" element, there is an undefined key that I need to store... How would I do so? Here is another example: (Notice the "300" that has no key to define the data, that is what I'm trying to store)
<item key="mod.dcc.heartbeat" label="" sev="none" time="1373475787">300</item>
There is always a string value in that position after the "time" key and I need to extract it....
Heres me code for using TBXML... I just need to "add" something to get that element....
TBXML *tbxml = [[TBXML alloc] initWithURL:url];
NSLog(@"TBXML: %@", tbxml);
TBXMLElement *status = tbxml.rootXMLElement;
NSString *statusString = [TBXML elementName:status];
NSLog(@"ROOT: %@", statusString);
TBXMLElement *itemElement = [TBXML childElementNamed:@"item" parentElement:status];
NSMutableDictionary *loggerData = [[NSMutableDictionary alloc] init];
do
{
NSString *key = [TBXML valueOfAttributeNamed:@"key" forElement:itemElement];
NSString *label = [TBXML valueOfAttributeNamed:@"label" forElement:itemElement];
NSString *sev = [TBXML valueOfAttributeNamed:@"sev" forElement:itemElement];
NSString *time = [TBXML valueOfAttributeNamed:@"time" forElement:itemElement];
NSString *data = [TBXML valueOfAttributeNamed:@"data" forElement:itemElement];
//NSLog(@"Key = %@ : Label = %@ : Sev = %@ : Time = %@ : Data = %@", key, label, sev, time, data);
NSArray *array = [[NSArray alloc] initWithObjects:label,sev, time, data, nil];
[loggerData setObject:array forKey:key];
} while ((itemElement = itemElement->nextSibling));
Edit
Changing NSString *data = [TBXML valueOfAttributeNamed:@"data" forElement:itemElement];
to NSString *itemValue = [TBXML textForElement:itemElement];
did the trick!!! Thank you thank you :)
Upvotes: 1
Views: 1020
Reputation: 52227
14459 and 300 are not keys, that are the values of two elements of kind item
try
NSString *itemValue = [TBXML textForElement:itemElement];
Upvotes: 1