0

我的应用程序中需要关系数据,其数据将从两个 XML 文件加载,这些文件将存储在assets文件夹中或从Server.

categories(id, name, slug) // using a slug string to select the category icon drawable in list view
places(id, name, ...., category_id)
images(id, path, place_id)

现在基于此构建了以下XML

类别.xml

<?xml version="1.0" encoding="utf-8"?>
<categories>
    <category>
        <name>Hill Station</name>
        <icon>hill-station</icon>
    </category>

    <category>
        <name>Water Fall</name>
        <icon>water-fall</icon>
    </category>
.
.
.
.

</categories>

地方.xml

<places>
    <place>
        <name>Nandi hills</name>
        <category>hill-station</category>
        <distance>70</distance>
        <days>1</days>
        <latitude>13.3333</latitude>
        <longitude>77.6500</longitude>
        <weather>Summer 25°-28°C, Winter 8°-10°C</weather>
        <todo>Para-Gliding, Tippu Drop, Gardens, Jumping Jacks</todo>
        <about>Nandi Hills or Nandidurg is an ancient hill fortress of southern India, 
            in the Chikkaballapur district of Karnataka state. It is located just 10 km from 
            Chickballapur town and approximately 60 km from the city of Bangalore. The hills are 
            nestled between the neighboring towns of Nandi, Muddenahalli, and Kanivenarayanapura.
            The hills are traditionally held as the origin of the Arkavathy river.
        </about>
        <images>
            <image>http://i.imgur.com/Y2MMa.jpg</image>
            <image>http://i.imgur.com/DoRXC.jpg</image>
            <image>http://i.imgur.com/ZA8PR.jpg</image>
            <image>http://i.imgur.com/aSeYa.jpg</image>
        </images>
    </place>

    <place>
        <name>Kemmannugundi</name>
        <category>hill-station</category>
        <distance>260</distance>
        <days>2</days>
        <latitude>13.5470</latitude>
        <longitude>75.7580</longitude>
        <weather>Summer 17°-34°C, Winter 12°-29°C</weather>
        <todo>Rajendra hill, Rock garden, Z point, Shiva temple</todo>
        <about>Kemmannugundi is a hill station in Tarikere taluk of Chikkamagaluru district in the state of Karnataka, India. 
            It is 1434m above sea level. This was the summer retreat of Krishnaraja Wodeyar IV and as a mark of respect to the king, 
            it is also known as Sri Krishnarajendra Hill Station. The station is ringed by the Baba Budan Giri Range, with cascades, 
            mountain streams, and lush vegetation, Kemmangundi’s has ornamental gardens and mountains and valleys views. 
            There is a spectacular sunset view from the Raj Bhavan.</about>
        <images>
            <image>http://i.imgur.com/Y2MMa.jpg</image>
            <image>http://i.imgur.com/DoRXC.jpg</image>
            <image>http://i.imgur.com/ZA8PR.jpg</image>
            <image>http://i.imgur.com/aSeYa.jpg</image>
        </images>
    </place>
</places>

我现在正在使用 OrderXMLHandler 来解析数据。是否有任何可以解析 xml 并自动提供对象的库?

4

1 回答 1

1

看看卡斯特。很多年前我用过。它似乎仍然是一个活跃的项目。它提供 XML/Object marsahlling/unmarshalling:http ://castor.codehaus.org/index.html

JAXB 提供了相同的功能,但我听说(即未证实)在 Android 上运行 JAXB 存在问题。

于 2013-01-06T04:54:13.030 回答