Guest User

Untitled

a guest
Jul 18th, 2018
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.50 KB | None | 0 0
  1. <catESAD_cu:GoodsDescription>КОЛПАЧОК</catESAD_cu:GoodsDescription>
  2. <catESAD_cu:GrossWeightQuantity>3649.192</catESAD_cu:GrossWeightQuantity>
  3. <catESAD_cu:NetWeightQuantity>2472.192</catESAD_cu:NetWeightQuantity>
  4. <catESAD_cu:NetWeightQuantity2>2472.192</catESAD_cu:NetWeightQuantity2>
  5. <catESAD_cu:InvoicedCost>16316.47</catESAD_cu:InvoicedCost>
  6. <catESAD_cu:CustomsCost>41048.05</catESAD_cu:CustomsCost>
  7. <catESAD_cu:StatisticalCost>20107.81</catESAD_cu:StatisticalCost>
  8. <catESAD_cu:GoodsTNVEDCode>7612100000</catESAD_cu:GoodsTNVEDCode>
  9.  
  10. private void button_downloadActionPerformed(java.awt.event.ActionEvent evt) {
  11. int returnVal = fileChooser.showOpenDialog(this);
  12. if (returnVal == JFileChooser.APPROVE_OPTION) {
  13. File file = fileChooser.getSelectedFile();
  14. try {
  15. txt_result.read( new FileReader( file.getAbsolutePath() ), null );
  16.  
  17.  
  18. } catch (IOException ex) {
  19. txt_result.setText("проблема с доступом к файлу"+file.getAbsolutePath()+ex);
  20.  
  21. }
  22. } else {
  23. txt_result.setText("Доступ к файлу отменен");
  24. }
  25.  
  26. }
  27.  
  28. XMLInputFactory factory = XMLInputFactory.newInstance();
  29. String status = "";
  30. try {
  31. // enable to switch namespaces support off, i.e. if namespace is not declared in xml
  32. // factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
  33.  
  34. XMLStreamReader xmlStreamReader = factory.createXMLStreamReader(new FileReader(file));
  35.  
  36. while(xmlStreamReader.hasNext()) {
  37. int eventType = xmlStreamReader.next();
  38. if(eventType == XMLStreamConstants.START_ELEMENT) {
  39. String name = xmlStreamReader.getLocalName();
  40. switch(name) {
  41. case "GoodsDescription":
  42. txt_GoodsDescription.setText(xmlStreamReader.getElementText());
  43. break;
  44. case "GrossWeightQuantity":
  45. txt_GrossWeightQuantity.setText(xmlStreamReader.getElementText());
  46. break;
  47. // TODO complete for all fields
  48. case "root": // replace by your document root if needed
  49. break;
  50. default:
  51. status += "Unknown element " + name + "n";
  52. }
  53. }
  54. }
  55. } catch(IOException | XMLStreamException ex) {
  56. status += "Error: " + ex;
  57. }
  58. txt_result.setText(status);
Add Comment
Please, Sign In to add comment