Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <catESAD_cu:GoodsDescription>КОЛПАЧОК</catESAD_cu:GoodsDescription>
- <catESAD_cu:GrossWeightQuantity>3649.192</catESAD_cu:GrossWeightQuantity>
- <catESAD_cu:NetWeightQuantity>2472.192</catESAD_cu:NetWeightQuantity>
- <catESAD_cu:NetWeightQuantity2>2472.192</catESAD_cu:NetWeightQuantity2>
- <catESAD_cu:InvoicedCost>16316.47</catESAD_cu:InvoicedCost>
- <catESAD_cu:CustomsCost>41048.05</catESAD_cu:CustomsCost>
- <catESAD_cu:StatisticalCost>20107.81</catESAD_cu:StatisticalCost>
- <catESAD_cu:GoodsTNVEDCode>7612100000</catESAD_cu:GoodsTNVEDCode>
- private void button_downloadActionPerformed(java.awt.event.ActionEvent evt) {
- int returnVal = fileChooser.showOpenDialog(this);
- if (returnVal == JFileChooser.APPROVE_OPTION) {
- File file = fileChooser.getSelectedFile();
- try {
- txt_result.read( new FileReader( file.getAbsolutePath() ), null );
- } catch (IOException ex) {
- txt_result.setText("проблема с доступом к файлу"+file.getAbsolutePath()+ex);
- }
- } else {
- txt_result.setText("Доступ к файлу отменен");
- }
- }
- XMLInputFactory factory = XMLInputFactory.newInstance();
- String status = "";
- try {
- // enable to switch namespaces support off, i.e. if namespace is not declared in xml
- // factory.setProperty(XMLInputFactory.IS_NAMESPACE_AWARE, false);
- XMLStreamReader xmlStreamReader = factory.createXMLStreamReader(new FileReader(file));
- while(xmlStreamReader.hasNext()) {
- int eventType = xmlStreamReader.next();
- if(eventType == XMLStreamConstants.START_ELEMENT) {
- String name = xmlStreamReader.getLocalName();
- switch(name) {
- case "GoodsDescription":
- txt_GoodsDescription.setText(xmlStreamReader.getElementText());
- break;
- case "GrossWeightQuantity":
- txt_GrossWeightQuantity.setText(xmlStreamReader.getElementText());
- break;
- // TODO complete for all fields
- case "root": // replace by your document root if needed
- break;
- default:
- status += "Unknown element " + name + "n";
- }
- }
- }
- } catch(IOException | XMLStreamException ex) {
- status += "Error: " + ex;
- }
- txt_result.setText(status);
Add Comment
Please, Sign In to add comment