about how to read the complicated xml file

Last blog,i had writed how to read one xml with a lot of instances,in which the instance is so easy,just with serveral members,now this blog will start to read more complicated xml ,the instance in which is not only the easy memebr,also with list<child-instance>.

 

1 .the xml is like:

<root>

   <parent>

         <id></id>

         <name></name>

         <child>

               <id></id>

               <name></name>

         </child>

         <child>

               <id></id>

               <name></name>

         </child>

         <child>

               <id></id>

               <name></name>

         </child>

         .

         .

         .

   </parent>

   <parent>

         <id></id>

         <name></name>

         <child>

               <id></id>

               <name></name>

         </child>

         <child>

               <id></id>

               <name></name>

         </child>

         <child>

               <id></id>

               <name></name>

         </child>

         .

         .

         .

   </parent>

</root>

 

 

 

2. setup class ,based on the parent and child

 

public class parent{


         private String parent_id;

         private String parent_name;

         List<child> childs = new ArrayList<child>();

         public parent(String parent_id,String parent_name,List<child> childs ){

                this.parent_id = parent_id;

                this.parent_name = parent_name;

                this.childs = childs;

         }

         // get and set

         .............................

}


public class child{


         private String child_id;

         private String child_name;

 

         public child (String child_id,String child_name){

                this.child_id = child_id;

                this.child_name = child_name;

 

         }

         // get and set

         .............................

}

 

3 . Read xml also using the xml pull

 

case XmlPullParser. END_TAG :

// 判断 child list

                  if (xpp.getName().equalsIgnoreCase( "child" ) && child != null ) {   

                        parent .setFilesizes( child );

                        size = null ;

                  }

// 包在外面的 tag—parent

                  if (xpp.getName().equalsIgnoreCase( "parent" ) && parent!= null && parents!= null ) {                                              

                        parents .add( parent );                           

                        parent = null ;

                  }

                 

                  else if (xpp.getName().equalsIgnoreCase( "root" )){

                done = true ;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值