不断读取特定文件夹中上传的XML数据并将数据提取到数据库 [英] Constantly read uploaded XML data from specific folder and extract data to database

查看:80
本文介绍了不断读取特定文件夹中上传的XML数据并将数据提取到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在冰岛现场,有一台仪器对从炉子中取出的材料进行化学分析。

该仪器使用软件编制分析报告(参见附件中的软件说明) )。



此报告信息需要发送到数据库,以便他们可以提取此信息。

我目前所做的是创建了一个网页,他们可以上传报告的导出的xml文件,然后这个网页提取数据并将其放入我们的现场服务器数据库。

什么现在需要自动执行此过程,因此不需要手动将xml文件上传到网页,而是需要编写应用程序来监视文件夹,如果有任何新的XML文件保存到文件夹,则需要从文件夹中提取数据。文件/文件并存储到数据库中。



我尝试过:



On site in Iceland the have an instrument that does chemical analysis of material they have tapped from the furnace.
This instrument uses software to draw up an report of the analysis (see attached doc on software).

This report information needs to be sent to a database whereby they can extract this information.
What I have done at the moment is I have created a webpage whereby they can upload an exported xml file of the report, this webpage then extracts the data and puts it into our server database on site.
What is required now is to automate this process, so instead of manually uploading the xml file to the webpage, an application needs to be written to monitor a folder and if any new XML files are saved to the folder the data needs to be extracted from the file/files and stored into a database.

What I have tried:

import java.io.IOException;

import javax.xml.parsers.DocumentBuilder;  
import javax.xml.parsers.DocumentBuilderFactory; 
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;	


public class Dom
{

	
   public static void main (String[] args)
   
   {
   String badnumber = "MPP";
   int badnumberconverted; 
   
   try {
      badnumberconverted = Integer.parseInt(badnumber);
   }catch (NumberFormatException nfEx){
  // System.out.println("banumber*1000000");
         }
      
               DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
      try {
               DocumentBuilder builder = factory.newDocumentBuilder();
               Document doc = builder.parse("repeat.xml");
               NodeList sampleIDs = doc.getElementsByTagName("Elements");
       for(int i=0;i<sampleIDs.getLength();i++){
               Node p = sampleIDs.item(i);
            if(p.getNodeType() == Node.ELEMENT_NODE){
               Element Elements = (Element) p;
               String id = Elements.getAttribute("id");
               NodeList nameList = Elements.getChildNodes();
             for(int j=0;j<nameList.getLength();j++){
               Node n = nameList.item(j);
             if(n.getNodeType() == Node.ELEMENT_NODE){
                Element name = (Element) n;
                  // System.out.println( convert(name.getTextContent()));
                System.out.println("Elements" + id + ":" + name.getTagName()+ "=" + name.getTextContent());
                  
                  }
               }
            }
         }     
      }  
               catch (ParserConfigurationException e){
      
                  e.printStackTrace();
      }
               catch (SAXException e)
      {
                  e.printStackTrace();
      }
                catch (IOException e){
         
                  e.printStackTrace();
      }
   }
   
  public static String convert(String val) 
   
   {
   
   double d = Double.parseDouble(val);
   d = d/1000000;
   
   return Double.toString(d);
   
                          
                      
        }    
   
   }

推荐答案

我无法帮助你在java抱歉 - 在c#中我会(可能,不知道你的任何要求)



a)写一个'Win32'服务

b)该服务将使用FileSystemWatcher FileSystemWatcher类(System.IO) [ ^ ]

c)添加文件

ci)正确名称

cii)有适当的内容

我会

d)extract&上传xml /数据并上传到您的数据库

e)ci&& ;;中没有匹配名称和/或内容的任何文件cii被放入一个错误文件并在以后报告

f)该服务将提供(通过某些界面)成功文件的统计数据与'错误'文件等



这可以分为两个不同的服务/应用程序,但可能是过度杀伤,这取决于上传的音量/频率等




$ c $ b在c#中,您可以使用'TopShelf'作为服务的基础 - 这可能值得一看 [NuGet Gallery | Topshelf.FileSystemWatcher 1.0.0.17](https://www.nuget.org/packages/Topshelf.FileSystemWatcher/) [ ^ ]





我很确定它的在java中很容易做到
I can't help you in java sorry - in c# I would (possibly, without knowing any more of your requirements)

a) write a 'Win32' service
b) the service would use FileSystemWatcher FileSystemWatcher Class (System.IO)[^]
c) when a file is added
ci) of the correct name
cii) with proper content
I would
d) extract & upload the xml/data and upload to your database
e) any files no matching name &/or content at ci && cii get put into an error file and reported on later
f) the service would provide (through some interface) stats on successful files vs 'error' files etc

This could be split into 'two different' services/apps, but maybe that's overkill, it depends on the volume/frequency of the uploads etc


in c#, you can use 'TopShelf' as the basis for a Service - this might be worthwhile looking at [NuGet Gallery | Topshelf.FileSystemWatcher 1.0.0.17](https://www.nuget.org/packages/Topshelf.FileSystemWatcher/) [^]


I'm pretty sure its easy enough to do in java


这篇关于不断读取特定文件夹中上传的XML数据并将数据提取到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆