从FTP解析XML编程 [英] Parsing XML from ftp to program

查看:522
本文介绍了从FTP解析XML编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问候,
我试图分析我从FTP收到的XML。我跟着一对夫妇教程,但他们没有工作,所以逢..我的code现在是:

Greetings, I'm trying to parse an XML I received from an FTP. I follow a couple of tutorials but they didn't work out so wel.. My code is now:

              URLConnection cn;
              URL url = new URL(SERVICE_URL);
              cn = url.openConnection();
              cn.connect();
              InputStream stream = cn.getInputStream();
              DocumentBuilder docBuild = DocumentBuilderFactory.newInstance().newDocumentBuilder();
              Document trDoc = docBuild.parse(stream);

              NodeList nodes = trDoc.getElementsByTagName("Name");

现在我必须得到名称在一个字符串并记录该字符串进行测试。有人可以帮我吗?

Now I have to get the Name in a string and log this string for testing. Can someone help me please?

编辑:
当我这样做:

When I do this:

         for (int i = 0; i < nodes.getLength(); i++){

              String toe = nodes.item(i).toString();
              Log.d("toe?",""+toe);
             // Log.d("nodes:",""+nodes.item(i))
              /*
            if (nodes.item(i).getTextContent().compareTo(original) == 0){
             System.out.println(nodes.item(i).getTextContent() + " > " + newValue);
             nodes.item(i).setTextContent(newValue);
            }*/
          }

我得到:

04-08 14:47:29.989: DEBUG/toe?(737): org.apache.harmony.xml.dom.ElementImpl@44c5d228

XML code是:

XML code is:

  <?xml version="1.0" encoding="UTF-8"?>
<Personnel>
  <Employee type="permanent">
        <Name>Seagull</Name>
        <Id>3674</Id>
        <Age>34</Age>
   </Employee>
  <Employee type="contract">
      <Name>Tom</Name>
</Personnel>

问候

推荐答案

查看最新的教程在我的博客:的 p-xr.com 结果
它配备了一个完整的源代码Eclipse项目

Check out the latest tutorial on my blog: p-xr.com
It comes with a full source Eclipse project

希望它帮助!

编辑:

尝试改变:

NodeList nodes = trDoc.getElementsByTagName("Name");

NodeList nodes = trDoc.getElementsByTagName("Employee");

这篇关于从FTP解析XML编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆