2010-11-29 2 views
0

I가 다음과 같은 XML 출력 :이 XML 데이터는 어떻게 추출합니까?

<info> 
    <ip>70.56.98.195</ip> 
    <host>70-56-98-195.slkc.qwest.net</host> 
    <country>UNITED STATES</country> 
    <cimg>http://localhost/ip-to-country/country-flags/us.png</cimg> 
</info> 
<searches> 
    <ips link="http://www.stopforumspam.com/search?q=70.56.98.195" title="Stop Forum Spam"></ips> 
    <ips link="http://openrbl.org/client/#70.56.98.195" title="Openrbl DNSBL RBL Blacklist"></ips> 
    <ips link="http://www.afrinic.net/cgi-bin/whois?searchtext=70.56.98.195" title="AfriNIC (Africa)"></ips> 
    <ips link="http://www.apnic.net/apnic-bin/whois2.pl?searchtext=70.56.98.195" title="APNIC (Asia Pacific region)"></ips> 
    <ips link="http://ws.arin.net/cgi-bin/whois.pl?queryinput=70.56.98.195" title="ARIN (North America, a portion of the Caribbean and sub-Saharan Africa)"></ips> 
    <ips link="http://lacnic.net/cgi-bin/lacnic/whois?query=70.56.98.195" title="LACNIC (Latin American and Caribbean region)"></ips> 
    <ips link="http://www.ripe.net/perl/whois?searchtext=70.56.98.195" title="RIPE (Europe, the Middle East and parts of Africa and Asia)"></ips> 
    <ips link="http://www.robtex.com/ip/70.56.98.195.html" title="Robtex"></ips> 
</searches> 

내 질문은, 밖으로 데이터를 당길 수있는 가장 좋은 방법은 무엇이며, 나는 내 XML 데이터를 퍼팅에서해야 더 좋은 방법이 있나요?

+1

* "XML 데이터를 저장하는 더 좋은 방법이 있습니까?"*. 어쨌든 잘 구성된 XML 문서는?! :) –

답변

1

꽤 좋은 도구는 Simple입니다. 데이터를 직렬화하는 간단한 객체를 작성하면됩니다. 예를 들어.

@Default 
private class Structure { 

    @Path("info") 
    private String ip; 

    @Path("host") 
    private String host; 

    @Path("path") 
    private String country; 

    @Path("path") 
    private String cimg; 

    @ElementList 
    private List<Entry> searches; 

    @Root 
    private static class Entry { 

     @Attribute 
     private String link; 

     @Attribute 
     private String title; 
    } 
} 

그런 다음 데이터를 개체 인스턴스로 읽어야합니다.

Serializer serializer = new Persister(); 
Structure structure = serializer.read(Structure.class, inputStream); 

이 프레임 워크는 거의 모든 안드로이드 버전에서 작동합니다. 자세한 내용은 Tutorial입니다.

관련 문제