I am new to programming, so to start with correct me if I am wrong in the paragragh below :
There is mainly three xml parsers for use in Android : Sax, Dom, and XmlPullParser. That last option, while existing as an external ressource. Is "in the core" of Android, thus working faster, but the functionnalities are limited
Ok here is my Question I slightly modified the code provided in the link below
http://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html
I did the following :
import java.io.IOException;
import java.io.StringReader;
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
import org.xmlpull.v1.XmlPullParserFactory;
public class xmlPParser
{
public String texte;
public xmlPParser (String arg)
throws XmlPullParserException, IOException
{
XmlPullParserFactory factory = XmlPullParserFactory.newInstance();
factory.setNamespaceAware(true);
XmlPullParser xpp = factory.newPullParser();
xpp.setInput( new StringReader ( arg ) );
int eventType = xpp.getEventType();
while (eventType != XmlPullParser.END_DOCUMENT)
{
//if(eventType == XmlPullParser.START_DOCUMENT) { System.out.println("Start document");}
// else if(eventType == XmlPullParser.START_TAG) { System.out.println("Start tag "+xpp.getName()); }
//else if(eventType == XmlPullParser.END_TAG) { System.out.println("End tag "+xpp.getName()); }
if(eventType == XmlPullParser.TEXT){ texte = xpp.getText(); } //{ System.out.println("Text "+xpp.getText());}
eventType = xpp.next();
}
//System.out.println("End document");
}
public String getTexte()
{
String returnTexte = texte;
return returnTexte;
}
}
In another java file, I can call the parser in the following way :
public xmlPParser myxpp;
...
myxpp = new xmlPParser("<foo>Hi five !!</foo>");
On that last line : I would like to be able to ask the parser to go to a file, instead of passing a string to it. how would i do that ? I am not sure how to make use of this posting Does getResources().getXml() supposes I am using the Android pullParser which I am not sure to be using now ?