I was having issues parsing XML, so I went through my code with NSLogs and noticed
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
was not called.
My XML:
<?xml version="1.0"?>
<locations>
<location>
<name>Americas</name>
<address></address>
<gid>CoQBdAAAAE2tdzw4RGvnvaUZTk6N1ByNtosmD--ZYfcmkkPkR6R6v_nN9gJCO1INOVg-S5rzy7BATEUmvAQzh8hClafZbph2wSgfD28gXNJAttXLUbqzQMaql3rVbisSUv2a2r_H6ktOSaI5lLvf0GNthT5jn2JfAdD_HfUls6qhMvrm5e5XEhDcF5uRjlfpSqI_aciS_QPaGhQVVHenbOKZBQMSoCzsoIsdfw313Q</gid>
<type>
<1>political</1><2/><3/><4/><5/>
</type>
<phone></phone>
<rating></rating>
<icon>http://maps.gstatic.com/mapfiles/place_api/icons/geocode-71.png</icon>
<website></website>
<longitude>-105.2551187</longitude>
<latitude>54.5259614</latitude>
</location>
</locations>
Relevant Part of my Implementation
- (void)viewDidLoad
{
[super viewDidLoad];
...
if(!self.distance){self.distance = #"250000";}
NSString *string = [NSString stringWithFormat:#"http://fishbe.in/lab/reserverr/api/?term=%#&lat=%f&long=%f&limit=100&distance=%#", self.searchterm, location.coordinate.latitude, location.coordinate.longitude, self.distance];
NSLog(#"%#", string);
NSURL *URL = [NSURL URLWithString:string];
NSXMLParser *parser = [[NSXMLParser alloc] initWithContentsOfURL:URL];
[parser setDelegate:self];
[parser setShouldResolveExternalEntities:NO];
[parser setShouldProcessNamespaces:NO];
[parser setShouldReportNamespacePrefixes:NO];
[parser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict {
self.element = elementName;
if ([self.element isEqualToString:#"locations"]) {
self.items = [[NSMutableArray alloc] init];
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string {
NSLog(#"HI"); //Not outputted
if ([self.element isEqualToString:#"name"]) {
self.result = [[ReserverrSearchResult alloc] init];
[self.result setTitle:string];
NSLog(#"%#", string);
} else if ([self.element isEqualToString:#"address"]) {
[self.result setVicinity:string];
NSLog(#"%#", string);
} else if ([self.element isEqualToString:#"gid"]) {
[self.result setGid:string];
NSLog(#"%#", string);
} else if ([self.element isEqualToString:#"latitude"]) {
[self.result setLatitude:[string floatValue]];
NSLog(#"%#", string);
} else if ([self.element isEqualToString:#"longitude"]) {
[self.result setLongitude:[string floatValue]];
NSLog(#"%#", string);
}
}
- (void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName {
if ([elementName isEqualToString:#"location"]) {
[self.items addObject:self.result];
}
}
- (void)parserDidEndDocument:(NSXMLParser *)parser {
[self addAnnotations];
}
Edit - Added
- (void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError
{
NSLog(#"%#",parseError);
}
and got nothing.
There are a couple of issues:
As wain points out, you should implement parser:parseErrorOccurred: and it will tell you what's wrong.
I'd expect problems if the searchterm contains any characters that are reserved characters for a URL (e.g. a space, a plus sign, an ampersand, etc.). You should always percent-escape what I presume is a user provided search term and adding it to a URL:
NSString *string = [NSString stringWithFormat:#"http://fishbe.in/lab/reserverr/api/?term=%#&lat=%f&long=%f&limit=100&distance=%#", [self percentEscapeString:self.searchterm], location.coordinate.latitude, location.coordinate.longitude, self.distance];
where you can use a method like the following:
- (NSString *)percentEscapeString:(NSString *)string
{
NSString *result = CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(kCFAllocatorDefault,
(CFStringRef)string,
(CFStringRef)#" ",
(CFStringRef)#":/?#!$&'()*+,;=",
kCFStringEncodingUTF8));
return [result stringByReplacingOccurrencesOfString:#" " withString:#"+"];
}
Note, do not rely upon stringByAddingPercentEscapesUsingEncoding to do the percent-escaping. You really want to use CFURLCreateStringByAddingPercentEscapes, like above.
As an aside, your XML is not well-formed. I don't believe that NSXMLParser will accept element names that are numbers. So, instead of:
<type>
<1>political</1><2/><3/><4/><5/>
</type>
You might want:
<types>
<type>political</type>
<type></type>
<type></type>
<type></type>
<type></type>
</types>
Or, if you really need those numeric identifiers:
<types>
<type id="1">political</type>
<type id="2"></type>
<type id="3"></type>
<type id="4"></type>
<type id="5"></type>
</types>
In this latter example, your didStartElement can then use the attributeDict to extract the id identifier.
You report that parseErrorOccurred did not return anything. That means your server probably didn't return anything. And this could be caused by any of a number of problems. Try using your URL and return the data (for example, into a NSString or NSData, rather than the parser) and see what the response looked like. E.g., for testing purposes you could do:
NSError *error;
NSData *data = [NSData dataWithContentsOfURL:url options:0 error:&error];
NSString *results = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// confirm error is `nil` and `results` is well-formed XML;
// you can then pass the `data` to `NSXMLParser` with `initWithData` if you want
I bet it's empty (which for certain search terms could be caused by a lack of percent-escaping, or from any of a myriad of server problems).
It might not be a problem, but it's worth noting that it's conceptually risky to save the results in foundCharacters, because sometimes between didStartElement and didEndElement, you'll have multiple calls to foundCharacters to retrieve the data. Generally people will instantiate a NSMutableString in didStartElement, append to it in foundCharacters, and then save it in didEndElement.
Related
I'm new to this web service in iOS. I made a sample web service app and made the first stage login successfully. While checking the url in web after login I got this output :
<Rows>
<Row>
<style>LW6001TA</style>
<thumbnail1>
/9j/4AAQSkZJRgABAQEAAAAAAAD/2wBDAAgGBgcGBQgHBwcJCQgKDBQNDAsLDBkSEw8UHRofHh0aHBwgJC4nICIsIxwcKDcpLDAxNDQ0Hyc5PTgyPC4zNDL/2wBDAQkJCQwLDBgNDRgyIRwhMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjIyMjL/wAARCAHCAV8DASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6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VfwD4tRmU+HtQyvXEJP8AKvr+igD4tvtB1fTW232mXluT08yFh/SqXkTZC+VJk9BtNfbrxpIMOisPQjNRfY7YsGNtFuHQ7BkUAfFP2W4HW3l/74NNMEoGTE4+qmvtr7PAf+WMf/fIprWdq4w1tCQexQUAfEm1vQ1IlvPIMxwyOPVVJr7R/sjTf+gfa/8Aflf8Kmis7aBdsVtEi+ioAKAPir7JdAZNtMP+2Z/wqMwTZ/1Un/fJr7cMERH+qT/vkU37Jbf8+8X/AHwKAPiZ7aeNd7wSqvqUIFRV9uyWltNGY5LeJ0PVWQEGsQeA/CgnM3/CPafvJyT5A6/TpQB8eil7V9ReKvhF4c8QWxNnbJpl4v3ZbdAFP+8vQ/zrzCT4DeKFnKpdaeyZ4fzGGR64xQB5Xzmpktrh/uQSsPZCa+lPAnwj0zwygu9UWLUNSP8AEy5jj/3Qep9zXoiWtvGMJBGo9kAoA+LY9K1GVgsdhdOT0Cwsc/pWlH4M8Ty/c0DUT/27t/hX2II0HRFH0FOoA+SrL4Y+M75gI9BuIwf4piIx+pruNB+Ad9Ntk13UY7de8Nt87f8AfR4H6177RQBxmi/Czwhou1otKS4mX/lpdEyH8jx+ldikaRIEjRURRgKowBTqKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigAooooAKKKKACiiigD/9k=
</thumbnail1>
</Row>
</Rows>
How to get these stuff back in Xcode and view it ? This is the first time I work on this web service I have no idea to get back this response back in Xcode. Please Help !
-(void)parseTheData
{
//Here convert your response to NSData type (NSData *data = [NSData data]; , i have used just for example)
NSData *data = [NSData data];
// Make sure that there is data.
if (data != nil) {
self.xmlParser = [[NSXMLParser alloc] initWithData:data];
self.xmlParser.delegate = self;
// Initialize the mutable string that we'll use during parsing.
self.foundValue = [[NSMutableString alloc] init];
// Start parsing.
[self.xmlParser parse];
}
}
//Delegate methods
-(void)parserDidStartDocument:(NSXMLParser *)parser{
// Initialize the array.
self.arrNeighboursData = [[NSMutableArray alloc] init];
}
-(void)parserDidEndDocument:(NSXMLParser *)parser{
// When the parsing has been finished then simply reload the table view or do what ever you want
}
-(void)parser:(NSXMLParser *)parser parseErrorOccurred:(NSError *)parseError{
NSLog(#"%#", [parseError localizedDescription]);
}
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict{
// If the current element name is equal to "geoname" then initialize the temporary dictionary.
if ([elementName isEqualToString:#"Row"]) {
self.dictTempDataStorage = [[NSMutableDictionary alloc] init];
}
// Keep the current element.
self.currentElement = elementName;
}
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qName{
if ([elementName isEqualToString:#"thumbnail1"]) {
// Store the data like this
[self.dictTempDataStorage setObject:[NSString stringWithString:self.foundValue] forKey:#"thumbnail1"];
}
else if ([elementName isEqualToString:#"style"]){
// Store the data like this
[self.dictTempDataStorage setObject:[NSString stringWithString:self.foundValue] forKey:#"style"];
}
else if ([elementName isEqualToString:#"Row"])
{
//Add the dictionary in array and remove the data from dictionary, so that we can reuse the dictionary
[self.arrNeighboursData addObject:self.dictTempDataStorage];
self.dictTempDataStorage = nil;
}
// Clear the mutable string.
[self.foundValue setString:#""];
}
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string{
// Store the found characters if only we're interested in the current element.
if (![string isEqualToString:#"\n"]) {
[self.foundValue appendString:string];
}
}
Here I am just showing you the way to move on.
I'm trying to gather the data from an XML file and add to an array. The data looks something like this..
<Placemark>
<name><![CDATA[Kingsway (Start)]]></name>
<description><![CDATA[]]></description>
<TimeStamp><when>2014-04-30T17:03:28.681Z</when></TimeStamp>
<styleUrl>#start</styleUrl>
<Point>
<coordinates>-1.408894,52.13977,176.0</coordinates>
</Point>
</Placemark>
<Placemark id="tour">
<name><![CDATA[Kingsway]]></name>
<description><![CDATA[]]></description>
<styleUrl>#track</styleUrl>
<ExtendedData>
<Data name="type"><value><![CDATA[running]]></value></Data>
</ExtendedData>
<gx:MultiTrack>
<altitudeMode>absolute</altitudeMode>
<gx:interpolate>1</gx:interpolate>
<gx:Track>
<when>2014-04-30T17:03:28.681Z</when>
<gx:coord>-1.408894 52.13977 176.0</gx:coord>
<when>2014-04-30T17:03:31.071Z</when>
<gx:coord>-1.407839 52.139166 174.0</gx:coord>
<when>2014-04-30T17:03:32.070Z</when>
<gx:coord>-1.407486 52.138963 175.0</gx:coord>
<when>2014-04-30T17:03:33.073Z</when>
<gx:coord>-1.407142 52.138755 174.0</gx:coord>
<when>2014-04-30T17:03:34.073Z</when>
<gx:coord>-1.406805 52.138555 173.0</gx:coord>
<when>2014-04-30T17:03:35.073Z</when>
<gx:coord>-1.40663 52.138441 173.0</gx:coord>
<when>2014-04-30T17:03:36.601Z</when>
<gx:coord>-1.405929 52.138027 172.0</gx:coord>
<when>2014-04-30T17:03:37.601Z</when>
<gx:coord>-1.405574 52.137817 172.0</gx:coord>
I'm only interested in the values following the tag gx:coord, so I'm parsing the file using the code below.
- (void)loadMap:(NSInteger)selJourney
{
NSString *journey = #"KML_Sample";
NSString *path = [[NSBundle mainBundle] pathForResource:journey ofType:#"kml"];
[self parseXMLFile:path];
}
- (void)parseXMLFile:(NSString *)pathToFile
{
NSXMLParser *addressParser;
[myParser setShouldProcessNamespaces:NO];
[myParser setShouldReportNamespacePrefixes:NO];
[myParser setShouldResolveExternalEntities:NO];
NSURL *xmlURL = [NSURL fileURLWithPath:pathToFile];
myParser = [[NSXMLParser alloc] initWithContentsOfURL:xmlURL];
[myParser setDelegate:self];
[myParser setShouldResolveExternalEntities:YES];
[myParser parse];
}
- (void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName attributes:(NSDictionary *)attributeDict
{
if ( [elementName isEqualToString:#"gx:coord"] ) {
polylineList = [[NSMutableArray alloc] init];
}
}
When the parser method runs and it finds the right elementName I want to retrieve the string data after the tag and add it to my NSMutableArray polylineList.
The other parameters in parser all return nil so am I missing something?
I managed to solve this myself using the method below
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if ((addRec) && (![string isEqualToString:#"\n"]))
{
NSArray *tmpArray = [[NSArray alloc] initWithObjects:string, nil];
if (polylineList.count > 0)
[polylineList addObject:string];
else
polylineList = [[NSMutableArray alloc] initWithArray:tmpArray];
}
}
I hope this is helpful to those who are using KML, MapKit or just parsing XML.
I am creating an IOS application. In which I have to use SOAP web-service to get some details. So that I have used SUDZ-C to generate the stub. I can able to call web-service and got the response. But I can't parse the response. The below is the XML response.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<soapenv:Body>
<ViewAppTrackResponse xmlns="http://service.cmp.app.com">
<ViewAppTrackResponseReturn>
<ns1:monthBO xmlns:ns1="http://response.cmp.app.com">
<monthListItem>
<ns2:date xmlns:ns2="http://bean.cmp.app.com">1-2-2014, Saturday (nonworking day)</ns2:date>
<ns3:lockStatus xmlns:ns3="http://bean.cmp.app.com">N</ns3:lockStatus>
<ns4:dailyTime xsi:nil="true" xmlns:ns4="http://bean.cmp.app.com"/>
<ns5:taskListNew xsi:nil="true" xmlns:ns5="http://bean.cmp.app.com"/>
</monthListItem>
<monthListItem>
<ns6:date xmlns:ns6="http://bean.cmp.app.com">2-2-2014, Sunday (nonworking day)</ns6:date>
<ns7:lockStatus xmlns:ns7="http://bean.cmp.app.com">N</ns7:lockStatus>
<ns8:dailyTime xmlns:ns8="http://bean.cmp.app.com">04:00</ns8:dailyTime>
<ns9:taskListNew xmlns:ns9="http://bean.cmp.app.com">
<taskListItem>
<ns9:trackId>1070</ns9:trackId>
<ns9:taskId>14</ns9:taskId>
</taskListItem>
<taskListItem>
<ns9:trackId>1094</ns9:trackId>
<ns9:taskId>44</ns9:taskId>
</taskListItem>
</ns9:taskListNew>
</monthListItem>
<monthListItem>
<ns10:date xmlns:ns10="http://bean.cmp.app.com">3-2-2014, Monday</ns10:date>
<ns11:lockStatus xmlns:ns11="http://bean.cmp.app.com">N</ns11:lockStatus>
<ns12:dailyTime xmlns:ns12="http://bean.cmp.app.com">08:00</ns12:dailyTime>
<ns13:taskListNew xmlns:ns13="http://bean.cmp.app.com">
<taskListItem>
<ns13:trackId>1071</ns13:trackId>
<ns13:taskId>14</ns13:taskId>
</taskListItem>
<taskListItem>
<ns13:trackId>1073</ns13:trackId>
<ns13:taskId>44</ns13:taskId>
</taskListItem>
</ns13:taskListNew>
</monthListItem>
</ns1:monthBO>
<ns14:userId xsi:nil="true" xmlns:ns114="http://response.cmp.app.com"/>5</ns14:userId>
</ViewAppTrackResponseReturn>
</ViewAppTrackResponse>
</soapenv:Body>
</soapenv:Envelope>
Can anyone help me to parse this response. This will helpful for me.
LibXML2 is included in Cocoa.
http://www.raywenderlich.com/553/xml-tutorial-for-ios-how-to-choose-the-best-xml-parser-for-your-iphone-project
http://www.cocoawithlove.com/2008/10/using-libxml2-for-parsing-and-xpath.html
You can use NSXMLParser class to parse this.Using its delegate methods you can parse. I am posting my try to parse your xml.It is not completed.I am giving you a basic code for parsing. You have to do the remaining.
Here "xmlInput" is of type NSString with your xmlstring.
NSData* xmlData = [xmlInput dataUsingEncoding:NSUTF8StringEncoding];
NSXMLParser * xmlParser = [[NSXMLParser alloc] initWithData:[xmlData copy]];
[xmlParser setDelegate:(id)self];
[xmlParser setShouldResolveExternalEntities: YES];
[xmlParser parse];
Create an xmlparser object and input your xmlData.Set its delegates.
//this delegate calls when parsing start.Only once.
- (void)parserDidStartDocument:(NSXMLParser *)parser
{
recordResults = NO;//declared in .h
MonthFlag = NO;//declared in .h
TaskFlag = NO;//declared in .h
Arry = nil;//declared in .h
}
// This delgate calls when each tag name is found.
-(void)parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *) namespaceURI qualifiedName:(NSString *)qName
attributes: (NSDictionary *)attributeDict
{
strElementName = [elementName copy];//strElementName is declared in .h
NSLog(#"%#",strElementName);
if([elementName isEqualToString:#"monthListItem"]){
MonthFlag = YES;
}
if([elementName isEqualToString:#"taskListItem"]){
TaskFlag = YES;
}
strElementValue = #""; //strElementValue is declared in .h
}
//This is called when each tag value is found.
-(void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
strElementValue = [NSString stringWithFormat:#"%#%#", strElementValue,[string copy]];
NSLog(#"%#",strElementValue);
//NSLog(#"%# : %#",strElmentName,strElementValue);
recordResults=(strElementValue.length > 0);
}
// This deleagte will call in the end of each tag name.
-(void)parser:(NSXMLParser *)parser didEndElement:(NSString *)elementName namespaceURI: (NSString *)namespaceURI qualifiedName:(NSString *)qName
{
NSLog(#"%# - %#",elementName,strElementValue);
if (recordResults) {
if (MonthFlag) {
if(dicTemp==nil){
dicTemp = [[NSMutableDictionary alloc] init];
for (int i=0; i<10; i++) {
[dicTemp setObject:#"" forKey:strElementName];
}
}
[dicTemp setObject:strElementValue forKey:elementName ];
}
}
if(([elementName isEqualToString:#"monthListItem"] ) && dicTemp!=nil) {
if(Arry==nil)Arry = [[NSMutableArray alloc] init];
[Arry addObject:[dicTemp copy]];
dicTemp = nil;
[dicTemp release];
MonthFlag = NO;
NSLog(#"arry test %#",[Arry description]);
}
}
// This delegate will call when parsing finishes . only once
- (void)parserDidEndDocument:(NSXMLParser *)parser
{
recordResults = NO;
}
I am trying to parse the XML from a URL in Xcode. The trouble I am having is with new line characters within the nodes. When I parse the following XML, I am getting the address perfectly fine but not the name or description. Also, if there happens to be a "&" symbol, the parser stops parsing. How do I get around these two obstacles?
Here is an example XML I am trying to parse:
<item>
<Name>
John Smith
</Name>
<Address>555 WHITEHEAD ST, Greenville, NY 55555</Address>
<Description>
Brick house - white trim
</Description>
</item>
<item>
<Name>
Jane Smith
</Name>
<Address>555 WHITEHEAD ST, Greenville, NY 55555</Address>
<Description>
Brick house - white trim & stone drive
</Description>
</item>
Here is the code I am using to parse the XML:
-(id) loadXMLByURL:(NSString *)urlString {
arrests = [[NSMutableArray alloc] init];
NSURL *url = [NSURL URLWithString:urlString];
NSData *data = [[NSData alloc] initWithContentsOfURL:url];
parser = [[NSXMLParser alloc] initWithData:data];
parser.delegate = self;
[parser parse];
return self;
}
-(void) parser:(NSXMLParser *)parser didStartElement:(NSString *)elementName namespaceURI:(NSString *)namespaceURI qualifiedName:(NSString *)qualifiedName attributes:(NSDictionary *)attributeDict
{
if([elementName isEqualToString:#"item"]) {
currentArrest = [[ArrestObject alloc] init];
}
}
-(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 ([elementName isEqualToString:#"channel"]) {
return;
}
if ([elementName isEqualToString:#"item"]) {
[self.arrests addObject:currentArrest];
currentArrest = nil;
}
else {
[currentArrest setValue:currentNodeContent forKey:elementName];
currentNodeContent = nil;
}
}
Any advice is greatly appreciated!
foundCharacters: can be called more than once per element. You need to append each string you get to your currentNodeContent variable, not just set it. So basically, reset currentNodeContent in the didStartElement method and use the fully appended value in the didEndElement method.
And you can't use stringByTrimmingCharactersInSet to get rid of the newlines because that only removes the whitespace from the ends of the string, not the middle.
Lastly, the problem with the & character is simple - it's not a valid character in XML. Whenever you need an actual & character in your XML, you need to use &, like in HTML. Same for < and > - use < and > respectively.
Update:
In didStartElement do:
currentNodeContent = [NSMutableString string];
In foundCharacters do:
[currentModeContent appendString:string];
I'm developing an iOS 4 application that parses a XML file. A piece of XML is:
<?xml version="1.0" encoding="utf-8" ?>
<cards>
<card id ="0">
<name lang="es">The Mad</name>
<description lang="es">...</description>
</card>
...
</cards>
I use the following method to parse <name lang="es">The Mad</name>.
#pragma mark -
#pragma mark NSXMLParserDelegate methods
- (void)parser:(NSXMLParser *)parser
didStartElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
attributes:(NSDictionary *)attributeDict
{
NSLog(#"DidStartElement: %#", elementName);
if ([elementName isEqualToString:#"card"])
{
currentCard = [[Card alloc] init];
NSString* arcaneNumber = [attributeDict objectForKey:#"id"];
currentCard.Number = arcaneNumber;
return;
}
if ([elementName isEqualToString:#"name"])
{
if ([[attributeDict objectForKey:#"lang"] isEqualToString:userLanguage])
{
currentProperty = kNameProperty;
return;
}
}
if ([elementName isEqualToString:#"description"])
{
if ([[attributeDict objectForKey:#"lang"] isEqualToString:userLanguage])
{
currentProperty = kDescriptionProperty;
return;
}
}
}
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string
{
if (!currentStringValue)
{
// currentStringValue is an NSMutableString instance variable
currentStringValue = [[NSMutableString alloc] initWithCapacity:50];
}
[currentStringValue appendString:string];
}
- (void) parser:(NSXMLParser *)parser
didEndElement:(NSString *)elementName
namespaceURI:(NSString *)namespaceURI
qualifiedName:(NSString *)qName
{
NSLog(#"DidEndElement: %#", elementName);
if ([elementName isEqualToString:#"card"])
{
[cards setObject:currentCard forKey:currentCard.Number];
[currentCard release];
currentCard = nil;
return;
}
if (currentProperty == kNameProperty)
{
currentProperty = kNoneProperty;
currentCard.Name = [currentStringValue stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
[currentStringValue release];
currentStringValue = nil;
return;
}
if (currentProperty == kDescriptionProperty)
{
currentProperty = kNoneProperty;
currentCard.Description = currentStringValue;
[currentStringValue release];
currentStringValue = nil;
return;
}
}
After, parsing , I get on currentStringValue the following:
\n\nThe Mad
How can avoid these two '\n'? Why am I getting these two '\n'?
This xml file came from a Windows system, and I've used TextWrangler to covert it to Classic Mac format.
The foundCharacters delegate method also gets called for whitespace in between elements. It will get called if there is say a newline between <cards> and <card id=....
I suggest clearing currentStringValue at the top of didStartElement to discard any characters found before the start of the current element and to make sure only the characters inside the current element (not between) are captured by foundCharacters.
At the top of didStartElement, add:
[currentStringValue release];
currentStringValue = nil;
It is possible for an element's value to contain whitespace (so removing them in didEndElement could result in saving values that don't match the xml content).
On your end element method you can try stripping these out yourself from the current text string. Simply try searching for them on the string and replace them with #"". I like replacing these and unwanted blank entries.
Try this it work for me ,
NSString *data= [str stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
Use above line of code in foundCharacters method .
- (void)parser:(NSXMLParser *)parser foundCharacters:(NSString *)string;
{
NSString *data= [string stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
if(dString == nil){
dString = [[NSMutableString alloc] initWithString:data];
}else
{
[dString appendString:data];
}
}
Hope this will help for some one .