Advertisement
Guest User

Untitled

a guest
Dec 3rd, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. public String GetXmlData()
  2. {
  3. DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
  4. DocumentBuilder builder = null;
  5. try
  6. {
  7. builder = builderFactory.newDocumentBuilder();
  8. InputStream is = getAssets().open("words.xml");
  9. Document document = builder.parse(new FileInputStream("C:\Users\Ocean\AndroidStudioProjects\Deneme1Project\Deneme1\build\res\assets\words.xml"));
  10. Element rootElement = document.getDocumentElement();
  11.  
  12. NodeList nodes = rootElement.getChildNodes();
  13.  
  14. for(int i=0; i<nodes.getLength(); i++){
  15. Node node = nodes.item(i);
  16.  
  17. if(node instanceof Element)
  18. {
  19. //a child element to process
  20. Element child = (Element) node;
  21. title = child.getAttribute("title");
  22. String author= child.getAttribute("author");
  23. String year= child.getAttribute("year");
  24. }
  25. }
  26. return title;
  27. }
  28. catch (Exception e)
  29. {
  30. e.printStackTrace();
  31. return e.toString();
  32. }
  33.  
  34. }
  35.  
  36. Document document = builder.parse(new FileInputStream("C:\Users\Ocean\AndroidStudioProjects\Deneme1Project\Deneme1\build\res\assets\words.xml"));
  37.  
  38. getAssets().open("words.xml");
  39.  
  40. File wordsXML = new File(Environment.getExternalStorageDirectory() + "/SomeFolderName/" + "words.xml");
  41. FileInputStream fis = new FileInputStream(wordsXML);
  42.  
  43. FileInputStream fis =(FileInputStream) getResources.openRawResource(R.raw.words);
  44.  
  45. InputStream is = (InputStream) getAssets().open("words.xml");
  46.  
  47. FileInputStream fis =(FileInputStream) getResources.openRawResource(
  48. R.raw.words);
  49.  
  50. Document document = builder.parse(new FileInputStream(fis));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement