因此,我正在编写一个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。如果有人能帮我这个忙,我将不胜感激。
谢谢
发布于 2012-04-09 12:32:57
您可以使用上面提到的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")方法来解析属性值。希望这能有所帮助。
https://stackoverflow.com/questions/10068805
复制相似问题