审查视图

src/main/java/com/tianbo/util/XML/MakeImfMeta.java 1.2 KB
朱兆平 authored
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
package com.tianbo.util.XML;

import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.io.SAXReader;
import org.xml.sax.SAXParseException;

import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.UnsupportedEncodingException;

public class MakeImfMeta {

    public static String makeImfDocument(String SNDR,String RCVR,String TYPE,String STYP,String DDTM,String SEQN,File Content) throws DocumentException,UnsupportedEncodingException,SAXParseException{
        Document document = DocumentHelper.createDocument();
        Element root = document.addElement( "MSG" );
        Element meta = root.addElement("META");
        meta.addElement("SNDR").addText(SNDR);
        meta.addElement("RCVR").addText(RCVR);
        meta.addElement("SEQN").addText(SEQN);
        meta.addElement("DDTM").addText(DDTM);
        meta.addElement("TYPE").addText(TYPE);
        meta.addElement("STYP").addText(STYP);

        SAXReader saxReader = new SAXReader();
//        saxReader.setEncoding("gb2312");
        Document doc = saxReader.read(Content);
        Element contentRoot = doc.getRootElement();
        root.add(contentRoot);


        return document.asXML();
    }
}