I've red something about them in Java and XML your visual blueprint book but actually i dont have a good definition about these kind of parsers.Let me to say that i've solved this problem as follows but give me any suggestion about this(your opinion).Remeber im doing a book for mobile so it will have a large amount of data.!So this is readXML() method:
I've declared a Vector[] chapterData that will holds data of each chapter.Let's say chapter one will have twenty pages with text so chapterData[0] takes all these pages and so on and so one,every chapterData[i] will hold text of each chapter than later i will display on Screen[], screens[i] takes chapterData[i]. So what do you thing am im doing anything that will be heavy for RAM of mobiles or even is there any easy method to do something like this(to get same result).?!
HTML Code:
int counter = 1;
boolean incremented = false;
public void readXML(KXmlParser parser) throws XmlPullParserException, IOException
{
parser.require(XmlPullParser.START_TAG, null, "title");
XmlNode node = new XmlNode(XmlNode.ELEMENT_NODE);
BookInformations bi = new BookInformations();
while(parser.nextTag() != XmlPullParser.END_TAG)
{
for(int i = 0; i < parser.getAttributeCount(); i++)
{
node.setAttribute(parser.getAttributeName(i),parser.getAttributeValue(i));
String attributeName = parser.getAttributeName(i);
String attributeText = parser.getAttributeValue(i);
if(attributeName.equals("index"))
{
bi.setIndex(attributeText);
}
else if(attributeName.equals("text"))
{
bi.setAttributeText(bi.getIndex()+"."+attributeText+"\n");
}
if(counter == Integer.parseInt(bi.getId()))
{
if(incremented == true)
{
//System.out.println("Incremented");
incremented = false;
}
else
{
if(chapterData[counter-1].contains(bi.getAttributeText()))
{
//System.out.println("True");
}
else if(bi.getAttributeText() == null)
{
}
else
{
chapterData[counter-1].addElement(bi.getAttributeText());
}
}
}
}
parser.require(XmlPullParser.START_TAG, null, null);
String name = parser.getName();
String text = parser.nextText();
if(name.equals("id"))
{
bi.setId(text);
}
else if(name.equals("name"))
{
bi.setName(bi.getId()+"."+text);
}
parser.require(XmlPullParser.END_TAG, null, name);
}
chapterNames.addElement(bi.getName());
chapterID.addElement(bi.getId());
parser.require(XmlPullParser.END_TAG, null, "title");
counter++;
incremented = true;
}