这是我的 XML。
<results keywords="ipod" limit="25">
<products count="30">
<product merchant_price="179.99"
network_id="2"
name = "ipod"
retail_price="179.99" />
<product merchant_price="189.99"
network_id="3"
name="ipod16gb"
retail_price="189.99" />
</products>
</results>
由此我需要单独获取产品属性。为此,我已经这样做了,我编写了一个解析器。
String xml = parser.getXmlFromUrl(url); // getting XML from the given URL
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName("product");
// looping through all item nodes
for (int i = 0; i < 10; i++) {
Element e = (Element) nl.item(i);
// adding each child node to HashMap key => value
Log.v("test",e.getAttribute("name"));
}
但是我无法正确获得价值并获得
NullPointerException
任何人都可以指出我在这里做错了什么吗?