做了一个英语练习题APP,去掉XML上的命名空间,写个总结


做了一个英语练习题APP,去掉XML上的命名空间,写个总结
17小时前
  这次算是感受到了数据结构有多么重要
  总结起来几点非常重要的经验
  第一点是设计方面
  和服务器通信的接口 要在开始之前就确定好
  宁可先不动手 也要先想清楚
  不能等开始后在临时加
  尤其是客户端方面的业务处理方式
  第二点也是传输方面
  尽量简化数据的传输次数
  吧交互次数尽可能的降低
  因为数据零碎 导致反复发请求
  这样处理起来费劲
  还容易混淆逻辑
  第三点是关于数据结构的
  尽量简化可不是说着玩的
  一个接口传过来十几个参数。。又不是神马大东西 这要人肿么受得了
  第四是关于XML的
  这几天确实呗折腾惨了
  不过折腾惨了的好处是 以后就不怕了
  例如:
  var xml:XML =
  
  There appears to be an error with the SQL database.There appears to be an error with the SQL database.There appears to be an error with the SQL database.
  
  
  ;
  然后赋值给字符串:
  var twoNS:Namespace = xml.namespace("");
  var str :String ;
  str = xml.twoNS::Option2;
  再用正则替换:
  var myPattern1:RegExp = //g;
  var myPattern3:RegExp = //g;
  str = str.replace(myPattern1, "" );
  str = str.replace(myPattern3, " " );
  这个时候 str内的结果是没有命名空间但是无法被解析的
  因为没有首尾标签:
  There appears to be an error with the SQL database.
  There appears to be an error with the SQL database.
  There appears to be an error with the SQL database.
  下来就简单了
  把str封起来
  str = "" + str +""
  然后在定义一个xml2 是我们最后的结果存放点
  var xml2:XML =
  
  ;
  最后一步 赋值:
  xml2.websites = XML(str);
  xml2的值就是:
  
  
  There appears to be an error with the SQL database.
  There appears to be an error with the SQL database.
  There appears to be an error with the SQL database.
  
  
  这样处理起来很爽
  一些细节就不说了
  为了整布局一宿没睡
  对flex布局有了一些认识
  相信对android 和 wing上的应用原理是一样的
  把xml去掉命名空间是自己想的
  费了老大劲 这几天确实被命名空间折腾惨了
  最狠的一次调用:
  var twoNS:Namespace = xml.namespace("");
  answer.text ="The answer is :  "+ xml.twoNS::GetActivityInfoResult.twoNS::SChoiceList.twoNS::SChoice[0].twoNS::Answer + "  and  " + xml.twoNS::GetActivityInfoResult.twoNS::SChoiceList.twoNS::SChoice[1].twoNS::Answer;
  我自己看着都晕了
  这样的访问出错率高达50%  

猜你喜欢

转载自sks485ro.iteye.com/blog/1359493