其实就是使用java下的解析xml的方法就可以了,我了解的不多,可以参考附录内容:

看看我的示例代码:

//取得内容
public Map<Integer,String> fetchArticleContent(int aId){
  Map<Integer,String> article = new HashMap<Integer,String>();
  
  try{
    URL url = new URL("http://www.aslibra.com/teach/article_data.xml");
    DocumentBuilderFactory factory=DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document doc = builder.parse(new InputSource(url.openStream()));
    NodeList nl = doc.getElementsByTagName("content");
    for (int i=0;i<nl.getLength();i++){
      article.put(i, doc.getElementsByTagName("content").item(i).getFirstChild().getNodeValue());
    }
  }catch(Exception e){
    e.printStackTrace();
  }
  return article;
}


这里节点比较简单,把需要的节点作为Map对象里面的元素,这样方便使用。
注意给程序访问互联网的权限,否则就进入Exception里面了。

也有sax的解析方式,不过稍微复杂了,这个还是看各自条件,sax方式可能在处理大的xml文件时比较实用。

参考内容:
1 java解析xml的4种经典方法
2 在Android中解析XML数据
3 Parsing XML from the Net - Using the SAXParser


原创内容如转载请注明:来自 阿权的书房
收藏本文到网摘
Tags: ,
十字架 Email
2011/01/25 15:30
Document doc = builder.parse(new InputSource(url.openStream()));这句通不过,DEBUG模式跳到异常里,权限已开放,求解
hqlulu 回复于 2011/01/25 17:22
看看异常是什么问题,FC也是会提示错误类型的
ddd
2010/12/09 11:04
请告诉我怎么解决,谢谢!
ddd
2010/12/09 11:03
我按照这么做 提示错误说权限被拒绝
hqlulu 回复于 2010/12/09 18:10
需要更详细的错误说明才行,你开DDMS,能够知道错误发生点在哪里
分页: 1/1 第一页 1 最后页
发表评论
表情
emotemotemotemotemotemotemotemotemotemotemotemotemot
emotemotemotemotemotemotemotemotemotemotemotemot
打开HTML 打开UBB 打开表情 隐藏
昵称   密码   游客无需密码
网址   电邮   [注册]
               

验证码 不区分大小写
 

阅读推荐

服务器相关推荐

开发相关推荐

应用软件推荐