My problems are several. It all compiles well, but I am not getting any output. From what I understand, the size of the arrays are 0, but I am not sure why. Even when I manually set the array lengths, I still don't get any output, so there appears to be something wrong on the functionality level. The tagPointers array is only storing zeroes, but is working in all other respects.
Here is the code
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserFactory;
import java.net.URL;
public class XmlPullRasterizer
{
XmlPullParserFactory factory;
XmlPullParser xpp;
URL url;
int[] tagPointers;
String[] attributePointers;
public XmlPullRasterizer(String uri) throws Exception
{
factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
xpp = factory.newPullParser();
url = new URL(uri);
xpp.setInput(url.openStream(), null);
this.tagPointers = new int[getRelevantTagCount()];
this.attributePointers = new String[getRelevantAttributeCount()];
}
public int getRelevantTagCount() throws Exception
{
int eventType = xpp.getEventType();
int tagCount = 0;
while (eventType != XmlPullParser.END_DOCUMENT)
{
if(isRelevantTag())
{
tagCount++;
}
eventType = xpp.next();
}
return tagCount;
}
public int getRelevantAttributeCount() throws Exception
{
int eventType = xpp.getEventType();
int attributeCount = 0;
while (eventType != XmlPullParser.END_DOCUMENT)
{
if(isRelevantTag())
{
attributeCount = attributeCount + xpp.getAttributeCount();
}
eventType = xpp.next();
}
return attributeCount;
}
public void setTagPointers() throws Exception
{
int eventType = xpp.getEventType();
int k = 0;
while (eventType != XmlPullParser.END_DOCUMENT)
{
if(eventType == XmlPullParser.START_TAG)
{
if(isRelevantTag())
{
if(xpp.getName() == "circle")
{
tagPointers[k] = 0;
}
else if(xpp.getName() == "ellipse")
{
tagPointers[k] = 1;
}
else if(xpp.getName() == "line")
{
tagPointers[k] = 2;
}
else if(xpp.getName() == "polygon")
{
tagPointers[k] = 3;
}
else if(xpp.getName() == "polyline")
{
tagPointers[k] = 4;
}
else if(xpp.getName() == "rectangle")
{
tagPointers[k] = 5;
}
else if(xpp.getName() == "text")
{
tagPointers[k] = 6;
}
k++;
}
}
eventType = xpp.next();
}
}
public void setAttributePointers() throws Exception
{
int eventType = xpp.getEventType();
int k = 0;
while (eventType != XmlPullParser.END_DOCUMENT)
{
if(eventType == XmlPullParser.START_TAG)
{
if(isRelevantTag())
{
int attributeCount = xpp.getAttributeCount();
for(int i = 0; i < attributeCount; i++)
{
attributePointers[k] = xpp.getAttributeValue(i);
k++;
}
}
}
}
}
public boolean isRelevantTag() throws Exception
{
if(xpp.getName() == "circle")
{
return true;
}
else if(xpp.getName() == "ellipse")
{
return true;
}
else if(xpp.getName() == "line")
{
return true;
}
else if(xpp.getName() == "polygon")
{
return true;
}
else if(xpp.getName() == "polyline")
{
return true;
}
else if(xpp.getName() == "rectangle")
{
return true;
}
else if(xpp.getName() == "text")
{
return true;
}
else
{
return false;
}
}
public static void main(String[] args)throws Exception
{
String uri = "file:///C:/Users/Matthew/Documents/NetBeansProjects/SVG/SVGDemo.svg";
XmlPullRasterizer pullRasterizer = new XmlPullRasterizer(uri);
pullRasterizer.setAttributePointers();
pullRasterizer.setTagPointers();
for(int i = 0; i < pullRasterizer.attributePointers.length; i++)
{
System.out.println(pullRasterizer.attributePointers[i]);
}
}
}
This post has been edited by Matamane: 13 July 2010 - 02:44 PM

New Topic/Question
Reply



MultiQuote





|