解析XML中的URL

要解析的string爲response

1.將字符串轉換城數據流對象InputStream

   ByteArrayInputStream in=new ByteArrayInputStream(response.getBytes());

2.將數據流轉化成document對象

  Document document =DocumentBuilderFactory.newInstance().newDocumentBuilder.Parse(in);

3.將document對象轉化城url

  Element root=document.getDocumetElement();

  NodeList nodes=root.getElementsByTagName("node");

  Node node=nodes.item(0);

   String url=node.getFirstChild().getNodeValue();

  return url;

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章