I'm working on an application where I use XML parsing in UITableView. I can not figure out how I'm separately parses attributes rok1 and rok2. If I use [_element isEqualToString: # "jmeno"] application works well, but it displayed to me in UITableView together rok1 and rok2 and do not want it. Thx for your help.
There is my parser code:
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
self.element = elementName;
if ([_element isEqualToString:#"rok1"])
{
_item = [[NSMutableDictionary alloc] init];
self.nazev = [[NSMutableString alloc] init];
self.definice = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([self.element isEqualToString:#"nazev"])
{
[self.nazev appendString:string];
}
else if ([self.element isEqualToString:#"def"])
{
[self.definice appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:#"rok1"])
{
Slova *thisSvatek = [[Slova alloc] initWithName:self.nazev
definice:self.definice];
[self.svatkyArray addObject:thisSvatek];
}
self.element = nil;
}
And example of my XML:
<?xml version="1.0" encoding="UTF-8" ?>
<menu>
<rok1>
<jmeno>
<nazev>Prvni</nazev>
<def>blblbla</def>
<jmeno>
<nazev>Druhy</nazev>
<def>blbablabal</def>
</jmeno>
</rok1>
<rok2>
<jmeno>
<nazev>Prvni</nazev>
<def>blblbla</def>
</jmeno>
</rok2>
</menu>
You need to keep track of your "state" as you are parsing the XML document. One simple approach is simply to add a boolean property that indicates that you are processing 'inside' the target element.
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
self.element = elementName;
if ([elementName isEqualToString:#"rok1"])
{
self.foundTarget=YES;
self.nazev = [[NSMutableString alloc] init];
self.definice = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (self.foundTarget) {
if ([self.element isEqualToString:#"nazev"])
{
[self.nazev appendString:string];
}
else if ([self.element isEqualToString:#"def"])
{
[self.definice appendString:string];
}
}
}
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:#"rok1"])
{
Slova *thisSvatek = [[Slova alloc] initWithName:self.nazev
definice:self.definice];
[self.svatkyArray addObject:thisSvatek];
self.foundTarget=NO;
}
self.element = nil;
}
A more sophisticated approach is to build some sort of data structure, such as a dictionary, that represents your XML
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
self.element = elementName;
if ([elementName isEqualToString:#"rok1"] || [elementName.isEqualToString:#"rok2"])
{
self.nazev = [[NSMutableString alloc] init];
self.definice = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([self.element isEqualToString:#"nazev"])
{
[self.nazev appendString:string];
}
else if ([self.element isEqualToString:#"def"])
{
[self.definice appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:#"rok1"] || [elementName.isEqualToString:#"rok2"])
Slova *thisSvatek = [[Slova alloc] initWithName:self.nazev
definice:self.definice];
self.rokDictionary[elementName]=thisSvatek; // self.rokDictionary is an NSMutableDictionary
}
self.element = nil;
}
To separate out the various 'jmeno' tags, you need to handle them in didStartElement & didEndElement -
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qualifiedName
attributes:(NSDictionary *)attributeDict {
self.element = elementName;
if ([elementName isEqualToString:#"rok1"] || [elementName.isEqualToString:#"rok2"])
{
self.jmenoArray=[NSMutableArray new];
}
else if ([elementName isEqualToString:#"jmeno"]) {
self.nazev = [[NSMutableString alloc] init];
self.definice = [[NSMutableString alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ([self.element isEqualToString:#"nazev"])
{
[self.nazev appendString:string];
}
else if ([self.element isEqualToString:#"def"])
{
[self.definice appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:#"jmeno"]) {
Slova *thisSvatek = [[Slova alloc] initWithName:self.nazev
definice:self.definice];
[self.jemnoArray addObject:thisSvatek];
}
else if ([elementName isEqualToString:#"rok1"] || [elementName.isEqualToString:#"rok2"])
self.rokDictionary[elementName]=self.jmenoArray; // self.rokDictionary is an NSMutableDictionary
self.jmenoArray=nil;
}
self.element = nil;
}
Related
How to parse the xml tags with empty values to get null values using NSXMLParser. I'm using the following code :
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:#"Video"])
{
isStatus = YES;
}
if ([elementName isEqualToString:#"ArrayOfVideo"])
{
isStatus = NO;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentNodeContent = (NSMutableString *)[string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if (isStatus)
{
if ([elementName isEqualToString:#"MediaOriginalFileName"])
{
[originalFileAry addObject:currentNodeContent];
}
if ([elementName isEqualToString:#"MediaType"])
{
[typeArray addObject:currentNodeContent];
}
if ([elementName isEqualToString:#"VideoMediaSource"])
{
[tableda addObject:currentNodeContent];
}
if ([elementName isEqualToString:#"VideoThumbnail"])
{
[tableImg addObject:currentNodeContent];
}
if ([elementName isEqualToString:#"VideoTitle"])
{
[tableData addObject:currentNodeContent];
}
}
}
here I'm not getting the empty values for the tag "VideoThumbnail".. Please help me to solve this...
this is what i tried ,and i found empty string, as expected from your example.
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
NSLog(#"the tag is %#",elementName);
if([elementName isEqualToString:#"VideoThumbnail"])
{
NSLog(#"video thumbnail tag arrived");
datastringThumbnail =[[NSMutableString alloc]init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if(datastringThumbnail)
{
datastringThumbnail = [NSMutableString stringWithFormat:#"%#",string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
{
if([elementName isEqualToString:#"VideoThumbnail"])
NSLog(#"the string is : %#",datastringThumbnail);
// [tableImg addObject:currentNodeContent];
// currentNodeContent is datastringThumbnail in my case
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
NSLog(#"the string we get is %#",datastringThumbnail);
}
FYI, datastringThumbnail is mutable string that will store you data of thumbnail tag(if any). As in your case there was no data in that tag, this string was empty. Use it wherever you want.
Actually, thing is that your method
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
}
is not being called since there are no data inside that particular data. So in following method ,you can do as follow :
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if (isStatus)
{
if ([elementName isEqualToString:#"VideoThumbnail"])
{
if([currentContent Length]>0)
{
[tableImg addObject:currentNodeContent];
}
else
{
[tableImg addObject:#" "];
}
}
}
}
forgive my indentation... Also TBXML parsing is much faster and easier way to work with xml parsing. you can directly give names of tags and their child nodes.
You try in
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
May be you get the getting the empty values for the tag "VideoThumbnail".
Following link useful for you.
https://developer.apple.com/library/ios/samplecode/SeismicXML/Listings/SeismicXML_APLParseOperation_m.html#//apple_ref/doc/uid/DTS40007323-SeismicXML_APLParseOperation_m-DontLinkElementID_11
My XML is looks like this :
<a>
<b>b1</b>
<c>c1</c>
<d>
<x>apple1</x>
<y>orange1</y>
<z>Mango1</z>
</d>
<d>
<x>apple2</x>
<y>orange2</y>
<z>Mango2</z>
</d>
<d>
<x>apple3</x>
<y>orange3</y>
<z>Mango3</z>
</d>
</a>
<a>
<b>b2</b>
<c>c2</c>
<d>
<x>apple4</x>
<y>orange4</y>
<z>Mango4</z>
</d>
<d>
<x>apple5</x>
<y>orange5</y>
<z>Mango5</z>
</d>
</a>
Here i want to count the number of <d>...</d> tag in each <a>...</a> in objectiveC. The answer will be 3 for first <a> tag and 2 for second <a> tag. Please give me a suggestion. Thanks.
Here is my code :
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementname isEqualToString:#"a"])
{
currentBook = [[BookListInfo alloc] init];
currentNodeContentBook=[[NSMutableString alloc] init];
isInChapterDTO = false;
}
else if ([elementname isEqualToString:#"d"])
{
//currentBook = [[BookListInfo alloc] init];
currentNodeContentChapters=[[NSMutableString alloc] init];
isInChapterDTO = true;
currentChapter = [[Chapters alloc] init];
}
}
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if(isInChapterDTO==TRUE)
{
if ([elementname isEqualToString:#"x"])
{
currentChapter.chapterId = currentNodeContentChapters;
}
if ([elementname isEqualToString:#"y"])
{
NSString*appendString=#"B";
currentNodeContentChapters=[appendString stringByAppendingString:currentNodeContentChapters];
currentChapter.chapterName = currentNodeContentChapters;
}
if ([elementname isEqualToString:#"z"])
{
currentChapter.chapterDurationAsSec = currentNodeContentChapters;
}
}
else
{
if ([elementname isEqualToString:#"b"])
{
[currentNodeContentBook stringByAppendingString:currentNodeContentBook];
currentBook.bookId = currentNodeContentBook;
}
if ([elementname isEqualToString:#"c"])
{
......................
}
}
}
if ([elementname isEqualToString:#"a"])
{
[bookListArray addObject:currentBook];
currentBook = nil;
currentNodeContentBook = nil;
}
else if ([elementname isEqualToString:#"d"])
{
[chapterListArray addObject:currentChapter];
//currentBook.ChapterList.Add(currentChapter);
currentChapter = nil;
isInChapterDTO = false;
}
Try this:
int dCount;
BOOL isATag;
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementname isEqualToString:#"a"])
{
isATag = YES;
}
else if ([elementname isEqualToString:#"d"])
{
if(isATag){
dCount++;
}
}
}
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementname isEqualToString:#"a"]){
NSLog(#"d tag count between A: %d",dCount);
dCount=0;
isATag = NO;
}
}
Declare the below objects
int count;
BOOL insideATag;
NSMutableArray *dCounts;
Initialize the dCounts in viewDidLoad
dCounts = [[NSMutableArray alloc]init];
Add the below delegate methods
- (void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementname isEqualToString:#"a"])
{
insideATag = YES;
count = 0;
}
}
- (void) parser:(NSXMLParser *)parser didEndElement:(NSString *)elementname namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([element isEqualToString:#"a"]){
insideATag = NO;
[dCounts addObject:count]
} else if ([elementname isEqualToString:#"d"] && insideATag)
{
count++;
}
}
If you want count of 'd' tags inside first 'a' tag, then
NSLog(#"Count of d : %i",[dCounts objectAtIndex:0]);
I have a XML file:
<trkseg>
<trkpt lat="11.004661" lon="76.97364"></trkpt>
<trkpt lat="11.005497" lon="76.97496"></trkpt>
</trkseg>
Here is my code:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:#"trkseg"])
{
self.tag = [[MRTRouteMapTag alloc]init];
NSLog(#"SRC: %#",[attributeDict objectForKey:#"lat"]);
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
[self.workingPropertyString appendString:string];
}
//event_logo, event_name, event_venue, event_date_time, race_details, event_descriptions;
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
if (self.tag)
{
NSString *trimmedString = [self.workingPropertyString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
// clear the string for next time
[self.workingPropertyString setString:#""];
if ([elementName isEqualToString:#"trkseg"])
{
[self.array addObject:self.tag];
self.tag = nil;
NSLog(#"Array Count ==>>>>>> %d", [self.array count]);
}
// Get Registered User Details
// ------ ------- ------------
else if ([elementName isEqualToString:#"trkpt"])
{
NSDictionary *attributeDict;
NSString *imageURLString = [attributeDict objectForKey:#"lat"];
self.tag.latitude = trimmedString;
NSLog(#"race_id ==>> %#", imageURLString);
}
}
}
Here I need to parse data from trkpt TAG of lat and lon value. Could any one guide me to achieve this.. Thanks in Advance.
lat and lon are not values, but attributes of node trkpt
They should be available to you at didStartElement like so:
[attributeDict objectForKey:#"lat"];
or
[attributeDict objectForKey:#"lon"];
This is not related to NSXMLPArser, but the XML structure itself.
The values that you are looking for are stored in the attributeDict dictionary in
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
At finally i find the solution to archive it..
Here i added my sample code..
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ([elementName isEqualToString:#"trkpt"])
{
self.tag = [[MRTRouteMapTag alloc]init];
lat = [attributeDict objectForKey:#"lat"];
lon = [attributeDict objectForKey:#"lon"];
tag.latitude = lat;
tag.longitude = lon;
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
[self.workingPropertyString appendString:string];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if (self.tag)
{
if ([elementName isEqualToString:#"trkpt"])
{
[self.array addObject:self.tag];
self.tag = nil;
}
}
}
I am using NSXMLParser to parse my XML with the following structure:
<characters>
<character>
<literal>本</literal>
<codepoint>
<cp_value cp_type="ucs">672c</cp_value>
<cp_value cp_type="jis208">43-60</cp_value>
</codepoint>
</character>
</characters>
I want to use the cp_value element's attribute_value as a key and the element value (e.g. 672c) as the value and place this key-value pair in my NSMutableDictionary *_codepoint. After parsing, I want the result (in the console) to look like this:
_codepoint: {
"ucs"=672c;
"jis208"=43-60;
}
As I have implemented the parser (code follows), I am getting this back in the console:
2013-01-22 22:12:46.199 MyApp[13391:c07] _codepoint: {
ucs = "\n \n ";
}
2013-01-22 22:12:46.201 MyApp[13391:c07] _codepoint: {
jis208 = "\n \n 672c\n ";
}
First - the values and keys are out-of-sync and second, the value for the jis208 element is not getting read-in. Second, I'm not sure what these \n and whitespaces are. Can anybody please give some advice?
The code I have written is:
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:#"characters"]) {
appDelegate.characters = [[NSMutableArray alloc] init];
} else if ([elementName isEqualToString:#"character"]) {
aCharacter = [[Character alloc] init];
} else if ([elementName isEqualToString:#"cp_value"]) {
if (!_codepoint) _codepoint = [[NSMutableDictionary alloc] init];
[_codepoint setValue:currentElementValue forKey:[attributeDict valueForKey:[[attributeDict allKeys] lastObject]]];
NSLog(#"_codepoint: %#", _codepoint);
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (!currentElementValue) {
currentElementValue = [[NSMutableString alloc] initWithString:string];
} else {
[currentElementValue appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:#"characters"]
// cp_values will be copied from a local NSMutableDictionary *_codepoint
|| [elementName isEqualToString:#"codepoint"]
) return;
if ([elementName isEqualToString:#"character"]) {
[appDelegate.characters addObject:aCharacter];
[aCharacter release];
} else if ([elementName isEqualToString:#"cp_value"]){
[aCharacter.codepoint addObject:_codepoint];
}
}
Thank you very much for looking.
problem is that you are adding currentElementValue to _codepoint before reading actual value into currentElementValue i.e you are adding it in when cp_value is started. you should add currentElementValue to _codepoint in didEndElement: delegate method.Then you'll get expected result.Modify your code like this:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:#"characters"]) {
appDelegate.characters = [[NSMutableArray alloc] init];
} else if ([elementName isEqualToString:#"character"]) {
aCharacter = [[Character alloc] init];
} else if ([elementName isEqualToString:#"cp_value"]) {
if (!_codepoint) _codepoint = [[NSMutableDictionary alloc] init];
currentAttributeKey = [[NSMutableString alloc]initWithString:[attributeDict valueForKey:[[attributeDict allKeys] lastObject]]];
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (!currentElementValue) {
currentElementValue = [[NSMutableString alloc] initWithString:string];
} else {
[currentElementValue appendString:string];
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:#"characters"] || [elementName isEqualToString:#"codepoint"])
return;
if ([elementName isEqualToString:#"character"]) {
[appDelegate.characters addObject:aCharacter];
[aCharacter release];
} else if ([elementName isEqualToString:#"cp_value"]){
[_codepoint setValue:[[currentElementValue componentsSeparatedByCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] componentsJoinedByString:#""] forKey:currentAttributeKey];
currentElementValue = [[NSMutableString alloc]init];
NSLog(#"_codepoint: %#", _codepoint);
[aCharacter.codepoint addObject:_codepoint];
}
}
where currentAttributeKey is NSMutableString that will store the attributes.In your case ucs and jis208
<events>
<status>OK</status>
<name>20121203</name>
<descripcion></descripcion>
<url_IOS></url_IOS>
<printers>
<coordenadas_LAT>40.44702054203392</coordenadas_LAT>
<coordenadas_LON>-3.703991174697876</coordenadas_LON>
</printers>
<printers>
<coordenadas_LAT>40.448416693004596</coordenadas_LAT>
<coordenadas_LON>-3.7036800384521484</coordenadas_LON>
</printers>
</events>
====
Hi All ,
I have this XML and Im parsing like that:
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
// the start of a 'booth' element is been encountered
if([elementName isEqualToString:#"events"])
{
self.tmpEvent = [[PublicPrivateEvent alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentElementValue = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:#"coordenadas_LAT"]) {
tmpEvent.latitude =currentElementValue;
}
if([elementName isEqualToString:#"coordenadas_LON"])
{
tmpEvent.longtitude = currentElementValue ;
}
if([elementName isEqualToString:#"description"])
{
tmpEvent.description = currentElementValue;
}
if([elementName isEqualToString:#"url_IOS"])
{
tmpEvent.imgurlios6 = currentElementValue;
}
if([elementName isEqualToString:#"printers"])
{
[printers addObject:tmpEvent];
currentElementValue = nil;
}
if([elementName isEqualToString:#"status"])
{
[events addObject:tmpEvent];
currentElementValue = nil;
}
}
===
I have 2 printers , but when im trying to get this 2 coordinates, but im getting only the last coordinate twice? What is the problem. Where am i wrong Could you help me?
Thanks in advance..
Yes. I was. Here below is my solution. Hope helps.
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
// the start of a 'booth' element is been encountered
if([elementName isEqualToString:#"evento"])
{
self.tmpEvent = [[PublicPrivateEvent alloc] init];
self.dictionaryPrinters = [[NSMutableDictionary alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
currentElementValue = (NSMutableString *) [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName
{
if ([elementName isEqualToString:#"coordenadas_LAT"]) {
[self.dictionaryPrinters setValue:currentElementValue forKey:#"coordenadas_LAT"];
tmpEvent.latitude =currentElementValue;
}
if([elementName isEqualToString:#"coordenadas_LON"])
{
[self.dictionaryPrinters setValue:currentElementValue forKey:#"coordenadas_LON"];
tmpEvent.longtitude = currentElementValue ;
}
if([elementName isEqualToString:#"description"])
{
tmpEvent.description = currentElementValue;
}
if([elementName isEqualToString:#"url_imagen_evento_LDPI"])
{
tmpEvent.imgurlldp = currentElementValue;
}
if([elementName isEqualToString:#"nombre"])
{
tmpEvent.name = currentElementValue;
}
if([elementName isEqualToString:#"url_imagen_evento_MDPI"])
{
tmpEvent.imgurlmdp = currentElementValue;
}
if([elementName isEqualToString:#"url_imagen_evento_HDPI"])
{
tmpEvent.imgurlhdp = currentElementValue;
}
if([elementName isEqualToString:#"url_imagen_evento_XHDPI"])
{
tmpEvent.imgurlxhdp = currentElementValue;
}
if([elementName isEqualToString:#"url_imagen_evento_IOS5"])
{
tmpEvent.imgurlios5 = currentElementValue;
}
if([elementName isEqualToString:#"url_imagen_evento_IOS6"])
{
tmpEvent.imgurlios6 = currentElementValue;
}
if([elementName isEqualToString:#"impresora"])
{
[printers addObject:[self.dictionaryPrinters copy]];
}
if([elementName isEqualToString:#"status"])
{
[events addObject:tmpEvent];
currentElementValue = nil;
}