【问题标题】:how can I get only data for nested element in xml using simple xml android如何使用简单的xml android仅获取xml中嵌套元素的数据
【发布时间】:2012-05-23 09:56:07
【问题描述】:

我希望有人能提供帮助,并且非常感激。

我正在尝试使用simple xml for android 从 xml 创建元素,我对根目录不感兴趣,而只对一些嵌套元素感兴趣。我想知道是否有一种方法可以让简单的 xml 获取这些元素,而无需我创建从 root 开始的所有类(在本例中为响应类)。我只对从下面的 xml 获取 Stations 类感兴趣。

谢谢。

    <Response xmlns="http://www.sss.com/ws/">
    <GroupInfo>
    <Id>lirr</Id>
    <Name>Long Island Rail Road</Name>
    <VehicleTypes>R</VehicleTypes>
    <Category>NYC to LI Regional Rail</Category>
    <IconLarge>
    <Width>50</Width>
    <Height>50</Height>
    </IconLarge>
    <Icon>
    <Width>25</Width>
    <Height>25</Height>
    </Icon>
    <Stations>
    <Station>
    <Id>albertson</Id>
    <Name>Albertson</Name>
    <X>-73.64169</X>
    <Y>40.77205</Y>
    <Radius>100</Radius>
    </Station>
    <Station>
    <Id>yaphank</Id>
    <Name>Yaphank</Name>
    <X>-72.91588</X>
    <Y>40.8256</Y>
    <Radius>100</Radius>
    </Station>
    </Stations>
    </GroupInfo>
    <ResponseStatus>
    <ResultCode>200</ResultCode>
    <ResultString>Success.</ResultString>
    </ResponseStatus>
    </Response>

【问题讨论】:

    标签: android xml xml-deserialization simple-framework


    【解决方案1】:

    我找到了解决方案。我使用@Path 来指定xpath,它解决了这个问题 http://simple.sourceforge.net/download/stream/doc/tutorial/tutorial.php#xpath

    【讨论】:

      猜你喜欢
      • 2012-05-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-06-12
      相关资源
      最近更新 更多