简体   繁体   中英

Get Array from XML file stored in url

I am trying to get all arrays I store in: https://s3.eu-west-2.amazonaws.com/tekstpieprz/strings.xml

I would like to use them for my textviews. I have added Unirest but cannot get my head around JSON. I have tried to play with something like:

HttpResponse<JsonNode> request = (HttpResponse<JsonNode>) Unirest.get("https://s3.eu-west-2.amazonaws.com/tekstpieprz/strings.xml")
            .getBody("docukrz");
    JSONObject myObj = request.getBody().getObject();
    final JSONArray results  = myObj.getJSONArray(String docukrz);

so then I can use the array in:

    final String[] docukrz = res.getStringArray(R.array.docukrz);

But instead using

Resources

I would like to use the array I store online. I do not fully understand how JSON works, I have only started learning JAVA 6 weeks ago. Any help would be much much appreciated.

You can find XML prase example here How can I parse xml from url in android? . according to that answer, your code should be like below

   URL url = new URL("https://s3.eu-west-2.amazonaws.com/tekstpieprz/strings.xml");
     DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
     DocumentBuilder db = dbf.newDocumentBuilder();
     Document doc = db.parse(new InputSource(url.openStream()));
     doc.getDocumentElement().normalize();

     NodeList nodeList = doc.getElementsByTagName("docukrz");
     ArrayList resourceList = new ArrayList();
      for (int i = 0; i < nodeList.getLength(); i++) {

          Node node = nodeList.item(i);
          resourceList.add(node);
 }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM