xml SAX parser can not retrive images in xml
Hello,
Can not xml SAX parser retrieve images from xml.
This is the xml code
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>itemChildren</key>
<array>
<dict>
<title>Roasted Garlic Jam</title>
<img>image1.png</img>
<desc>
Ingredients:
4 heads garlic, large roasted
1 and peeled
2 teaspoon olive oil
1 tablespoon fresh lemon juice
1/2 teaspoon kosher salt
1 tablespoon Italian parsley, coarsely
1 chopped
1 cayenne pepper, pinch
1 ground pepper, fresh
1. Chop garlic with knife until it forms a paste. 2. Place in a bowl, add
remaining ingredients. Stir to blend. 3. Use for bruschetta, pizza or grilled meats. Yield 2/3 cup.
</desc>
</dict>
</array>
</dict>
</plist>
This is code
package com.EaseApps.jamrecipes;
import java.io.IOException;
import java.util.List;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;
import org.xml.sax.Attributes;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;
import android.content.Context;
import android.util.Log;
public class xmlAnalyzer extends DefaultHandler {
// Used to define what elements we are currently in
private boolean inImg = false;
private boolean inTitle = false;
private boolean inDesc = false;
// Feed and Article objects to use for temporary storage
private List<String> detailsItem = null;
private List<String> menuItem = null;
private List<String> ImgItem = null;
private String currentMenu = "", currentDetail = "", currentImg = "";
public void startElement(String uri, String name, String qName,
Attributes atts) {
if (name.trim().equals("title"))
inTitle = true;
else if (name.trim().equals("img"))
inImg = true;
else if (name.trim().equals("desc"))
inDesc = true;
}
public void endElement(String uri, String name, String qName)
throws SAXException {
if (name.trim().equals("title")) {
inTitle = false;
menuItem.add(currentMenu);
currentMenu = null;
} else if (name.trim().equals("img")) {
inImg = false;
ImgItem.add(currentImg);
currentImg = null;
} else if (name.trim().equals("desc")) {
inDesc = false;
detailsItem.add(currentDetail);
currentDetail = null;
}
}
public void characters(char ch[], int start, int length) {
String chars = (new String(ch).substring(start, start + length));
try {
if (inTitle) {
currentMenu = chars;
} else if (inImg) {
currentImg = chars;
} else if (inDesc) {
currentDetail = currentDetail + chars;
}
} catch (Exception e) {
Log.e("NewsDroid", e.toString());
e.printStackTrace();
}
}
public xmlAnalyzer(Context ctx, List<String> detail, List<String> menu,
List<String> img) {
detailsItem = detail;
menuItem = menu;
ImgItem = img;
try {
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
xr.setContentHandler(this);
xr.parse(new InputSource(ctx.getAssets().open("recipe.xml")));
} catch (IOException e) {
Log.e("Recipe", e.toString());
e.printStackTrace();
} catch (SAXException e) {
Log.e("Recipe", e.toString());
e.printStackTrace();
} catch (ParserConfigurationException e) {
Log.e("Recipe", e.toString());
e.printStackTrace();
}
}
@Override
public void endDocument() throws SAXException {
}
}
anyone pls help me it's urgent.
Thanks.