views:

540

answers:

1

Hi all, I'm experiencing some performance problem using XML parser with iphone sdk. I tried to use LibXML parser directly and the NSXMLParser, but i had the same results. Now I'm looking for something that can improve parsing performance. Moving attributes to a nested elements can make it faster?

I got an XML source file like this:

<Events>
 <Event Name="Test1" Description="Desc" Cat="Cate" Date="20/01/2010" ImageURL="" />

</Events>

Do I have to create a nested tree ? Such as the folliwing ? Does it improve the performance?

<Events>
 <Event>
  <Name>Test1</Name>
  <Description>A description</Description>
  <Date>20/01/2010</Date>
  <ImageURL>http://remoteurl.../foo.png&lt;/ImageURL&gt;
 </Event>
</Events>

Thx a lot, Paolo

A: 

I am not entirely sure what you mean. I may not be understanding you correctly but here is what I did in my program.

Assume you have a file like this:

<document>

 <person>
  <name>bob</name>
  <phone>555-5555</phone>
   <vehicle>
    <color>blue</color>
    <type>truck</truck>
   </vehicle>
 </person>

 <person>
  <name>jan</name>
  <phone>444-5555</phone>
   <vehicle>
    <color>red</color>
    <type>car</truck>
   </vehicle>
 </person>

</document>

When you hit a person tag, lets assume your going to create a person object. So you create that person object and you let it parse the xml inside of the person tags. You do this by making the person object the new delegate of the object. When the person object discovers the closing person tag it can reset the delegate. I also went ahead and re-called the same method on the original delegate. I got this idea from here. You can also follow and do the same thing for the vehicle tag. I am sure you can understand what I am driving at now.

The reason why I think this improves efficiency is that rather than creating a stack of elements and also stepping back in the stack (like when you see a person checking to see if your in a document be fore that). I suppose that you could just assume when you see a person tag that your in a person but if you want to be on the safe side checking is important. Also this way is more modular. I think because of the reduction in string compares performance would improve. Its also more elegant to code.

If this is not the kinda answer your looking for could you provide a little detail. Thanks and happy coding.

startoftext