Skip to content

Instantly share code, notes, and snippets.

@pk11
Created May 19, 2010 02:10
Show Gist options
  • Save pk11/405866 to your computer and use it in GitHub Desktop.
Save pk11/405866 to your computer and use it in GitHub Desktop.
@As(Runnable.class)
void feedReader() {
try {
List<String> titles = new ArrayList<String>();
//for this example, let's use a file
VTDGen vg = new VTDGen();
File f = new File("./myfeed.xml");
FileInputStream fis = new FileInputStream(f);
byte[] b = new byte[(int) f.length()];
fis.read(b);
//VTDGen takes a buffer, in this case a file
vg.setDoc(b);
vg.parse(false);
VTDNav vn = vg.getNav();
AutoPilot ap = new AutoPilot(vn);
//turn off name space awerness
ap.selectElement("item");
while(ap.iterate()){
vn.toElement(VTDNav.FIRST_CHILD,"title");
Log.v(TAG,"element name(should print title):" + vn.toString(vn.getCurrentIndex()));
int t = vn.getText();
if (t!=-1) {
Log.v(Tag,"value "+vn.toNormalizedString(t));
titles.add(vn.toNormalizedString(t));
}
}
//Do something with titles
}
catch (Exception e){
System.out.println(" Exception during navigation "+e);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment