views:

29

answers:

2

I have some XML which looks like this:

<?xml version='1.0'?>
<methodResponse>
    <params>
        <param>
            <value><array><data>
                <value><array><data>
                    <value><dateTime.iso8601>20100508T14:49:56</dateTime.iso8601></value>
                    <value><string></string></value>
                    <value><string>comment</string></value>
                    <value><string></string></value>
                    <value><string>Milestone milestone1 deleted</string></value>
                    <value><int>1</int></value>
                </data></array></value>
            </data></array></value>
        </param>
    </params>
</methodRepsonse>

NSXMLParser seems to not be giving any data back for the blank values resulting in an array with 4 items in it instead of 6.

Is there anything I can do to NSXMLParser to make it return an empty string for the blank values so that I can maintain the order of the data when it is returned?

A: 

Not quite sure I understand your problem here. NSXMLParser would at least report the beginning and end of the elements. Would that not be enough the get them in the right order?

willcodejavaforfood
+1  A: 

So after whipping up a quick sample with a delegate that just prints out what's happening during parsing I don't see anything at all wrong with what's being parsed.

I suspect however that you're relying on an incorrect expectation that between calls to didStartElement... and didEndElement... you should get a foundCharacters... call with an empty string? My question is based on the way you phrased the title of your question because there's no such thing as a "blank value." Either there is a value, or there isn't.

Imagine instead your XML contained <string/> instead of the exactly equivalent <string></string>. You still get start/end notifications.

You should be creating your NSMutableString (presumably the type that you're using for your <string> elements) in didStartElement... when <string> is found, appending to that string IF foundCharacters... is called (it can get called more than once with the value in chunks), and tossing it into your array when it's done on didEndElement....

If you really want to be more robust, you'll also be wanting detect an error condition if you find the start of a new element before your string ends, assuming that it is in fact an error for you.

imaginaryboy