java - 在Java中提取XML属性(ISBNDB)

标签 java android xml parsing

所以我正在编写一个 Android 应用程序,需要从网络上获取图书价格数据。我发现 isbndb.com 似乎提供了很好的理由和价格比较。唯一的问题是它们的 xml 文件有点复杂。

我是用 Java 解析 XML 的新手,了解不多。我知道如何解析基本的 xml 文件。带有简单的标签。我通常使用 DocumentBuilder 和 DocumentBuilderFactory 但这是我试图解析的文件的一部分。

<Prices price_time="2012-04-08T20:05:49Z">
<Price store_isbn="" store_title="Discworld: Thief of Time" store_url="http://isbndb.com/x/book/thief_of_time/buy/isbn/ebay.html" store_id="ebay" currency_code="USD" is_in_stock="1" is_historic="0" check_time="2008-12-09T12:00:51Z" is_new="0" currency_rate="1" price="0.99"/>
<Price store_isbn="" store_title="" store_url="http://bookshop.blackwell.com/bobus/scripts/home.jsp?action=search&type=isbn&term=0061031321&source=1154376025" store_id="blackwell" currency_code="USD" is_in_stock="0" is_historic="0" is_new="1" check_time="2011-11-08T02:54:15Z" currency_rate="1" price="7.99"/> 
</Prices> 

我想做的是获取属性值中的信息,例如 store_isbn 或 store_title。如果有人能帮助我,我将非常感激。

谢谢

最佳答案

您可以使用上面提到的link为了解析 xml 和检索属性值,您可以使用以下内容。

    public void startElement(String uri, String localName,String qName, 
            Attributes attributes) throws SAXException {

    System.out.println("Start Element :" + attributes.getValue("store_title"));




}

attributes.getValue("store_title") 方法将用于解析属性值。希望它会有所帮助。

关于java - 在Java中提取XML属性(ISBNDB),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10068805/

相关文章:

java - Oracle 应用服务器上每个 Java VM 的单独 GC 日志文件

android - 如何使 Relativelayout 可点击?

ruby - XML 到哈希转换 : Nori drops the attributes of the deepest XML elements

xml - 无法让 Saxon-CE 工作

java - Android studio - 带Retrofit2的外汇汇率API,无法运行应用程序

java - 如何修复缺少 Artifact 的 POM?

android - 非法参数异常 : column '_id' does not exist when call to SimpleCursorAdaptor

javascript - 从 E4X 复制的 XML 中删除命名空间属性

java - Crouton 库中的滚动文本

Android Facebook 集成不注销