开发者

XML parsing with sub nodes

开发者 https://www.devze.com 2023-02-22 16:31 出处:网络
I need some guidance about XML parsing. in my case I have to parse XML it looks like -<food-drive>

I need some guidance about XML parsing. in my case I have to parse XML it looks like

-<food-drive>
−<coordinator cordid="4">
       <name>Luis Abarca</name>
       <teamname>A parents</teamname>
       <target>$3,500.00</target>
       <received>$0.00</received>
       −<image>
        alink
       </image>
−<teammember count="1">
   −<member memid="3">
      <membername>Rub</membername>
      <email>ssn@gmail.com</email>
      <phone>(323) 807-3920</phone>
   </member>
</teammember>
</coordinator>
−<coordinator cordid="9">
     <name>Jani</name>
     <teamname>Woori's LA Keeper</teamname>
     <target>$200.00</target>
     <received>$0.00</received>
     −<image>
          alink
     &开发者_如何学Pythonlt;/image>
</coordinator>
−<coordinator cordid="11">
    <name>Jan</name>
    <teamname>Woori LA Keeper</teamname>
    <target>$200.00</target>
    <received>$0.00</received>
   −<image>
       alink
    </image>
</coordinator>
−<coordinator cordid="13">
   <name>Julio Torres</name>
   <teamname>Our Town El Sereno</teamname>
   <target>$1,000.00</target>
   <received>$0.00</received>
  −<image>
      alink
   </image>
</coordinator>
</food-drive>

Here , the tag [coordinator] is main tag and the tag [teammember] is inner tag but this tag appears rarely. Now I want to parse this xml and store the data. I am confuse how store the data because [coordinator] tag may have more then one [teammember] tag !!! any suggestion ?


Keep a mutable array of the team members and one object which points at "current".

If you're using the built-in XML parser, you would in didStartElement: allocate and put a new team member into the array, and set the object to point at it.

This way subsequent entries related to team members would be able to address that object for populating the data.

0

精彩评论

暂无评论...
验证码 换一张
取 消