解析器用于读取具有相同XSD和XSLT的多个XML文件。

huangapple 未分类评论44阅读模式
标题翻译

Parser to read multiple xml file with same XSD and XSLT

问题

我想基于XSD文档从多个XML文件中读取数据而一个XML文件的结构与另一个文件不同但将遵循XSD模式此外这些XML是嵌套的XML有人可以帮助我吗这样我就可以使用已经创建的实用程序并向其添加属性我需要一个XML解析器它根据XSD模式解析每个XML文件它们是不同的),并返回一个映射列表以便可以将数据与数据库数据匹配

import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class Test {
    public static void main(String[] args) {

        Customer customer = new Customer();
        
        try {

            File file = new File("SalesPoslog20200225104558676.xml");
            JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
            Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

            // output pretty printed
            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

            jaxbMarshaller.marshal(customer, file);
            jaxbMarshaller.marshal(customer, System.out);

        } catch (JAXBException e) {
            e.printStackTrace();
        }

    }

}

import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Customer {
    int organizationID;
    int retailStoreID;
    int workstationID;
    int tillID;
    int sequenceNumber;
   
    public int getOrganizationID() {
        return organizationID;
    }

    @XmlElement
    public void setRetailStoreID(int retailStoreID) {
        this.retailStoreID = retailStoreID;
    }

    public int getWorkstationID() {
        return workstationID;
    }

    @XmlAttribute
    public void setRetailStoreId(int retailStoreID) {
        this.retailStoreID = retailStoreID;
    }

}
英文翻译

I want to read the data from multiple XML files based on the XSD document and the structure of one XML file will not be the same as to another but will follow the xsd schema. Also, the xmls are nested xmls.Can someone help me with it so that I can use the already created utility and add the attributes to it? I need a XML parser which parses each xml file(They are different) based on the xsd schema and returns me a list of the map so that the data can be matched with the DB data.

import java.io.File;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Marshaller;

public class Test {
    public static void main(String[] args) {

        Customer customer = new Customer();
        
        try {

            File file = new File("SalesPoslog20200225104558676.xml");
            JAXBContext jaxbContext = JAXBContext.newInstance(Customer.class);
            Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

            // output pretty printed
            jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

            jaxbMarshaller.marshal(customer, file);
            jaxbMarshaller.marshal(customer, System.out);

        } catch (JAXBException e) {
            e.printStackTrace();
        }

    }

}


import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;

@XmlRootElement
public class Customer {
    int organizationID;
    int retailStoreID;
    int workstationID;
    int tillID;
    int sequenceNumber;
   
    public int organizationID() {
        return organizationID;
    }

    @XmlElement
    public void RetailStoreID(int  retailStoreID) {
        this.retailStoreID = retailStoreID;
    }

    public int workstationID() {
        return workstationID;
    }

    

    @XmlAttribute
    public void RetailStoreId(int RetailStoreId) {
        this.retailStoreID = retailStoreID;
    }

}

huangapple
  • 本文由 发表于 2020年3月16日 21:04:25
  • 转载请务必保留本文链接:https://java.coder-hub.com/60706553.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定