我发送一个URL请求,我用System.out.println(sendURL("www.xxxx"))结果是一段XML类似以下信息<response>
<lst name="responseHeader"></lst>
 <result name ="response" numFound="222">
  <doc>
   <str name="zs">zhangsan</str>
   <str name="ls">lisi</str>
   <int name="ww">wangwu</int>
   <int name="qq">qq</int>
  <!--很多doc-->
   </doc>
   <doc>
   <str name="zs2">zhangsan2</str>
   <str name="ls2">lis2i</str>
   <int name="ww2">wangwu2</int>
   <int name="qq2">qq2</int>
   </doc>
   </result>
   <lst name="11">
   <ls name='a'/>
   <ls name='b'/>
   </lst>
</response>
如何用java接受他返回的信息呢?我要提取出这个XML文件的相关信息
以前解析XML都是需要..getResourceAsStream("db-config.xml") 里面的参数是一个文件名。可是我发送的URL,在我调用sendRUL这个方法后。用System.out.printlt()打印 

解决方案 »

  1.   

    你可以去搜索下Dom4j,网上相关的例子很多。
      

  2.   

    DOM4J  SAX  这两个就足够了。
      

  3.   


    Document doc = DocumentHelper.parseText(sendURL("www.xxxx"));//String解析为xml
    //Document doc = new SAXReader().read(is);//传入的是InputStreamElement root = doc.getRootElement();http://hi.baidu.com/%B7%E7%C7%E5%D1%EFjava/blog/item/ba93aade86f6d61a63279881.html
      

  4.   

    File f = xxxxx;
    DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
    org.w3c.dom.Element element = builder.parse(f).getDocumentElement();
      

  5.   

    用dom4j ,http://blog.csdn.net/liuc0317/article/details/6439187
    把那个代码拷下来,修改就可以