Go Back   MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Reply
 
Thread Tools Search this Thread Display Modes
Old Jun 3, 2008, 09:18 AM   #1
sujithkrishnan
macrumors 6502
 
Join Date: May 2008
Location: Bangalore
Send a message via Yahoo to sujithkrishnan
[iPhone] NSXMLParser problem

Hi all.

i am making us eof the NSXMLParser in my iPhone app.
What i am facing now is that in my xml file i am having characters like

<items>
<item>my favourites</item>
<item>BOOKS & DVDs</item>
<item>itemNameTM products</item>
</items>

issue is that the foundCharacters method is returning me "BOOKS" , "&", "DVDs" in separately.

Actually it should return :BOOKS & DVDs" as a single string, isnt it?

the problem is there whereever i use "&", "trademark symbol" etc....
Its giving "my favourites" as a single string, means the problem is not because of whitespaces.

I tried appending all the strings that i got using appendString method of NSString class.

But the resulting string is displayed as "Books....." .
Its not because of the space limitation, i think the string is appending some miscs...

Please help me...

I got stuck up with my application...
sujithkrishnan is offline   0 Reply With Quote
Old Jun 3, 2008, 09:42 AM   #2
DerekS
macrumors regular
 
Join Date: Jun 2007
I don't think the & symbol is valid in an XML tag. I think you need to use:

&amp;
DerekS is offline   0 Reply With Quote
Old Jun 3, 2008, 10:00 AM   #3
lazydog
macrumors 6502a
 
Join Date: Sep 2005
Location: Cramlington, UK
Send a message via MSN to lazydog
Also, I think it's a good idea to not to rely on text to be contained in a single text node, ie you may need to concatenate sequential text nodes.

b e n
lazydog is offline   0 Reply With Quote
Old Jun 4, 2008, 03:58 AM   #4
sujithkrishnan
Thread Starter
macrumors 6502
 
Join Date: May 2008
Location: Bangalore
Send a message via Yahoo to sujithkrishnan
Quote:
Originally Posted by DerekS View Post
I don't think the & symbol is valid in an XML tag. I think you need to use:

&amp;

Yeah.. its actually '&amp' only when u open the file in DashCode, But in safari it will show as "&" only.

So my question is why foundCharacters: method stops when some special chars get encoutered?

ie... from <item>Books & DVDs</item>

foundCharacters: method is returning "Books" , "&" , "DVDs" separately in 3 separate method calls.
I am expecting entire string to get returned in a one call....
sujithkrishnan is offline   0 Reply With Quote
Old Jun 4, 2008, 10:17 AM   #5
iSee
macrumors 68040
 
iSee's Avatar
 
Join Date: Oct 2004
Quote:
Originally Posted by sujithkrishnan View Post
Yeah.. its actually '&amp' only when u open the file in DashCode, But in safari it will show as "&" only.

So my question is why foundCharacters: method stops when some special chars get encoutered?

ie... from <item>Books & DVDs</item>

foundCharacters: method is returning "Books" , "&" , "DVDs" separately in 3 separate method calls.
I am expecting entire string to get returned in a one call....
The documentation does state that a single text value can be returned in pieces. In this particular case I'd guess it is returning this in three separate pieces because "&" is represented in the XML as "&amp;". The event driven parser is a low-level, low-overhead parser. It probably doesn't want to maintain any unnecessary state or do any unnecessary conversions. In this case, for example, it would have to convert the string "BOOKS &amp; DVDs" (the way the characters exist in the source document) to "BOOKS & DVDs" (the way you would like to receive the text). The overhead of doing that conversion could add up, especially if there are large text nodes with a lot of entity references. It would be especially wasteful to do the conversion if the client doesn't need it (remember, NSXMLParser is a general class so it doesn't know whether or not it would help you to combine the parts for you).

Anyway, there are surely other, less obvious reasons the parser might break a text node value apart. It's an implementation detail that you can't predict. The behavior could also change in a future update.

So you're stuck. Your code will have to handle the concatination itself.
iSee is offline   0 Reply With Quote
Old Jun 5, 2008, 06:42 AM   #6
psingh01
macrumors 65816
 
Join Date: Apr 2004
this is how the parsers in java work as well. they don't always return one string and you have to concatenate the strings. using a stack to keep track of the element you are in will do the trick.
psingh01 is offline   0 Reply With Quote

Reply
MacRumors Forums > Apple Systems and Services > Programming > Mac Programming

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Similar Threads
thread Thread Starter Forum Replies Last Post
NSXMLParser MickeyT iPhone/iPad Programming 3 Jun 18, 2014 04:29 PM
iPhone 3GS problems - there is a problem with your iPhone Mat246 iPhone 17 Mar 13, 2013 04:14 AM
NSXmlParser error leconteconte iPhone/iPad Programming 2 Feb 28, 2013 06:29 AM
Resolved: NSXMLParser fails after first element? ArtOfWarfare Mac Programming 2 Jul 17, 2012 07:30 PM

Forum Jump

All times are GMT -5. The time now is 05:19 AM.

Mac Rumors | Mac | iPhone | iPhone Game Reviews | iPhone Apps

Mobile Version | Fixed | Fluid | Fluid HD
Copyright 2002-2013, MacRumors.com, LLC