package com.sy.utils; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import org.dom4j.io.SAXReader; import java.io.ByteArrayInputStream; import java.io.UnsupportedEncodingException; public class MakeImfMeta { public static String makeImfDocument(String SNDR,String RCVR,String TYPE,String STYP,String DDTM,String SEQN,String Content) throws DocumentException,UnsupportedEncodingException{ 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(); Document doc = saxReader.read(new ByteArrayInputStream(Content.getBytes("GB2312"))); Element contentRoot = doc.getRootElement(); root.add(contentRoot); return document.asXML(); } }