Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sujithkrishnan

macrumors 6502
Original poster
May 9, 2008
265
0
Bangalore
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...
 

DerekS

macrumors 6502
Jun 25, 2007
341
14
I don't think the & symbol is valid in an XML tag. I think you need to use:

&
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
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
 

sujithkrishnan

macrumors 6502
Original poster
May 9, 2008
265
0
Bangalore
I don't think the & symbol is valid in an XML tag. I think you need to use:

&


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....
 

iSee

macrumors 68040
Oct 25, 2004
3,540
272
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 "&". 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 & 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.
 

psingh01

macrumors 68000
Apr 19, 2004
1,586
629
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.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.