Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7172545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:38:12+00:00 2026-05-28T15:38:12+00:00

me again, sorry :) I was using dom parser to get xml from web

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:38:13+00:00Added an answer on May 28, 2026 at 3:38 pm

    I have done it ! took about 4 hours to learn it and figure it out.. and lots and lots of googling 😀

    but here is how I did it, maybe somebody can use it also:

    URI lUri = new URI(getString(R.string.url)); //get url from strings
    
    // 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();
    
    // Prepares the request
    HttpClient lHttpClient = new DefaultHttpClient();
    HttpGet lHttpGet = new HttpGet();
    lHttpGet.setURI(lUri);
    lHttpGet.addHeader(BasicScheme.authenticate(new UsernamePasswordCredentials("user", "pass"), "UTF-8", false));
    
    // Sends the request and read the response
    HttpResponse lHttpResponse = lHttpClient.execute(lHttpGet);
    InputStream lInputStream = lHttpResponse.getEntity().getContent();
    
    DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = factory.newDocumentBuilder();
    Document dom = builder.parse(lInputStream);
    
    Element root = dom.getDocumentElement();
    NodeList nl = root.getElementsByTagName(KEY_ITEM);
    
    // pass data to another function...
    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);
    }
    

    Working so far, its not the best solution I guess but hey! its working 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using the Ajax Form jQuery plugin to get JSON from a server: /**
I am using PHP to generate some XML. I need to put quotes in
Hey all, Sorry its me again. This time I have a question that I
Sorry to bother again, but I really need help transforming this Python2 code into
Again with the soap. I am trying to build a header using soap4r that
Hello again ladies and gents! OK, following on from my other question on ASP.NET
Me again... I have an XML File that contains different categories which I would
Hi Again Masters Of The Web :) Now, I have got a new stupid
Sorry for opening this topic again, but thinking about this topic itself has started
Sorry, I completely neglected to mention that I'm using Python. Let me try this

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.