有好几个月没写代码了,最近有个项目需要透过 internet 动态去网上读取 xml 数据,带的小弟还没类似经验,所以花了几分钟写了段示例代码:

import  org.jdom.input.SAXBuilder;
import  org.jdom.Document;
import  org.jdom.Element;
import  java.net.URL;

public   class  XML
{
    
public   static   void  main(String[] args) 
    
{
        
try
        
{
            SAXBuilder sax 
=   new  SAXBuilder();
            URL url 
=   new  URL(" http://www.dsd.com/dsd.xml" );
            Document doc 
=  sax.build(url);
            Element root 
=  doc.getRootElement();
            Element row 
=  root.getChild( " Row " );            
            String jtsl 
=  row.getChildTextTrim( " JTSJ " );
            String jtbj  =  row.getChildTextTrim( " JTBJ " );
            String xjsj  =  row.getChildTextTrim( " XJSJ " );
            String xjbj  =  row.getChildTextTrim( " XJBJ " );
            System.out.println(jtsl);
        }

        
catch  (Exception e)
        
{
            e.printStackTrace();
        }

        
    }

}