me again, sorry :)
I was using dom parser to get xml from web and parse it and put the data in db.. all was fine and dandy but than I put basic authentication for folder where the xml is on web...
before it worked like this:
final String URL = getString(R.string.url);
// XML node keys
final String KEY_ITEM = "plan"; // parent node
final String KEY_NAME = "agent";
final String KEY_DATE = "date";
final String KEY_SHIFT = "shift";
final String KEY_LINE = "line";
XMLhandler parser = new XMLhandler();
String xml = parser.getXmlFromUrl(URL); // getting XML
Document doc = parser.getDomElement(xml); // getting DOM element
NodeList nl = doc.getElementsByTagName(KEY_ITEM);
// empty table
db.dropData("plan");
for (int i = 0; i < nl.getLength(); i++) {
Element e = (Element) nl.item(i);
String name = parser.getValue(e, KEY_NAME);
String date = parser.getValue(e, KEY_DATE);
String shift = parser.getValue(e, KEY_SHIFT);
String line = parser.getValue(e, KEY_LINE);
db.createList(name, date, shift, line); // add to db
}
How do I implement authentication to this ? I know I should use something like:
Authenticator.setDefault(new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(
"user", "password".toCharArray());
}
});
from what I was looking over this forum, and google... but so far no luck, I do not understand java so good ( still learning ) how do I do it ? I mean how do I get the xml after authentication to parser, I ended up with stream and parser wants string...
I know I might not be making much sense :)
Vlad.