0

I'm using https://github.com/nicklockwood/XMLDictionary category to convert server XML response into NSDictionary. It only seem to work half of the time, and I'm not sure if it's a problem with the way I'm using it, or if there's a bug in XMLDictionary or what.

I'm calling the method like this: NSDictionary *convertedData = [NSDictionary dictionaryWithXMLData:data];

Here's an example of XML data I'd like to parse (This is directly from the "data" I'm passing):

<?xml version="1.0" encoding="utf-8"?>
<anime>
  <entry>
    <id>572</id>
    <title>Kaze no Tani no Nausicaa</title>
    <english>Nausica&auml; of the Valley of the Wind</english>
    <synonyms>Nausicaa of the Valley of the Wind; Warriors of the Wind</synonyms>
    <episodes>1</episodes>
    <score>8.47</score>
    <type>Movie</type>
    <status>Finished Airing</status>
    <start_date>1984-03-11</start_date>
    <end_date>1984-03-11</end_date>
    <synopsis>A thousand years after a global war, a seaside kingdom known as the Valley Of The Wind remains one of only a few areas still populated. Led by the courageous Princess Nausica&auml;, the people of the Valley are engaged in a constant struggle with powerful insects called ohmu, who guard a poisonous jungle that is spreading across the Earth. Nausica&auml; and her brave companions, together with the people of the Valley, strive to restore the bond between humanity and the Earth. &lt;br /&gt;
&lt;br /&gt;
(Source: Disney)</synopsis>
    <image>http://cdn.myanimelist.net/images/anime/7/42071.jpg</image>
  </entry>
</anime>

And here's what I get as a result:

Printing description of convertedData:

{
    "__name" = anime;
    entry =     {
        english =         {
        };
        id = 572;
        title = "Kaze no Tani no Nausicaa";
    };
}

The thing is that this doesn't happen with all search results. It's perfectly repeatable by using the same search results but there's certain results in which it doesn't do it at all. I can't figure out what's special about those results that makes it work where others don't. Here's an example of one that does work.

XML Input:

<?xml version="1.0" encoding="utf-8"?>
<anime>
  <entry>
    <id>329</id>
    <title>Planetes</title>
    <english></english>
    <synonyms></synonyms>
    <episodes>26</episodes>
    <score>8.42</score>
    <type>TV</type>
    <status>Finished Airing</status>
    <start_date>2003-10-04</start_date>
    <end_date>2004-04-17</end_date>
    <synopsis>In the year 2075, mankind has reached a point where journeying between Earth, the moon and the space stations is part of daily life. However, the progression of technology in space has also resulted in the problem of the space debris, which can cause excessive and even catastrophic damage to spacecrafts and equipment. This is the story of Technora&amp;#039;s Debris Collecting section, its EVA worker, Hachirota &amp;quot;Hachimaki&amp;quot; Hoshino, and the newcomer to the group, Ai Tanabe. &lt;br /&gt;
&lt;br /&gt;
(Source: ANN)</synopsis>
    <image>http://cdn.myanimelist.net/images/anime/8/50463.jpg</image>
  </entry>
  <entry>
    <id>10735</id>
    <title>Planetes Picture Drama</title>
    <english></english>
    <synonyms>Planetes Audio Drama</synonyms>
    <episodes>9</episodes>
    <score>6.27</score>
    <type>Special</type>
    <status>Finished Airing</status>
    <start_date>2009-09-25</start_date>
    <end_date>2009-09-25</end_date>
    <synopsis>Planetes picture drama.</synopsis>
    <image>http://cdn.myanimelist.net/images/anime/9/29571.jpg</image>
  </entry>
</anime>

NSDictionary Output:

{
    "__name" = anime;
    entry =     (
                {
            "end_date" = "2004-04-17";
            episodes = 26;
            id = 329;
            image = "http://cdn.myanimelist.net/images/anime/8/50463.jpg";
            score = "8.42";
            "start_date" = "2003-10-04";
            status = "Finished Airing";
            synopsis = "In the year 2075, mankind has reached a point where journeying between Earth, the moon and the space stations is part of daily life. However, the progression of technology in space has also resulted in the problem of the space debris, which can cause excessive and even catastrophic damage to spacecrafts and equipment. This is the story of Technora&#039;s Debris Collecting section, its EVA worker, Hachirota &quot;Hachimaki&quot; Hoshino, and the newcomer to the group, Ai Tanabe. <br />\n<br />\n(Source: ANN)";
            title = Planetes;
            type = TV;
        },
                {
            "end_date" = "2009-09-25";
            episodes = 9;
            id = 10735;
            image = "http://cdn.myanimelist.net/images/anime/9/29571.jpg";
            score = "6.27";
            "start_date" = "2009-09-25";
            status = "Finished Airing";
            synonyms = "Planetes Audio Drama";
            synopsis = "Planetes picture drama.";
            title = "Planetes Picture Drama";
            type = Special;
        }
    );
}

Sometimes it will only omit certain tags, like the tag. Other times it will omit mostly everything like in my first example. I'm really confused.

Also, if I pass it a large XML file (say a search result with 50 items in it), it'll only parse half of it. I doubt anyone wants to read through all of it but just in case, here's the XML http://pastebin.com/aQTc8S9x and here's the NSDictionary that comes out http://pastebin.com/MwuexaZV

Joseph Toronto
  • 1,882
  • 1
  • 15
  • 29

1 Answers1

1

Looks like it is being tripped up by &auml; and other html entities. Handle them first on the XML String before passing to the parser. Here is another SO question on how to do that.

Community
  • 1
  • 1
coneybeare
  • 33,113
  • 21
  • 131
  • 183
  • Thank you so much. You hit the nail right on the head. I ended up using this solution and it works perfectly now. http://stackoverflow.com/a/5163810/1495070 – Joseph Toronto Dec 29 '13 at 21:55