Why is my SAX handler returning an object with no values? I am setting it just fine
- by Blankman
I'm writing a SAX parser for an xml, and the object it returns doesn't have the values that I am setting in the events.
My classes structure is like this:
public class ProductSAXHandler extends DefaultHandler {
private Product product;
public ProductSAXHandler() {
product = new Product();
}
public Product ParseXmlFile(String xml) {
SAXParserFactory spf = new ...
XMLReader parser = ....
parser.parse(xml);
return product;
}
public void StartElement(....) {
for(int ...) { // looping through attributes
if(qName == "description" && name == "sku") {
product.setSKU(value);
}
}
}
}
When I am in debug mode, the value of product does get set, and I can see that the product's sku field has the correct value.
But for some reason the product object returned is just a new Product object with no values set during the parsing.
What am I doing wrong here? It must be me not understanding how these events are fired etc.