首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > XML SOAP >

xml合拢

2012-09-11 
xml合并利用xslt模板进行合并/* * 合并xml文件 */public void testMerge() throws Exception{String aa

xml合并

利用xslt模板进行合并

/* * 合并xml文件 */public void testMerge() throws Exception{String aa = "F:/workspace/bme/mystudy/uconfig/11.xml";String bb  = "F:/workspace/bme/mystudy/uconfig/22.xml";System.out.println(XmlUtil.DOM2String(mergeDocumentByXslt(getDocumentByUrl(aa),getDocumentByUrl(bb))));}    private Document mergeDocumentByXslt(Document defaultDocument, Document mergedDoc) throws Exception    {    TransformerFactory factory =  new TransformerFactoryImpl();    InputStream in = new File("F:/workspace/bme/mystudy/uconfig/uconfig-merge.xslt").toURL().openStream();    Templates templates = factory.newTemplates(new StreamSource(in));        Transformer transformer = templates.newTransformer();        javax.xml.transform.Source source = new DOMSource(defaultDocument);        NodeSet nodeSet = new NodeSet(mergedDoc.getChildNodes());        transformer.setParameter("with", nodeSet);        Document transformedDoc = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();        DOMResult result = new DOMResult(transformedDoc);        transformer.transform(source, result);        return transformedDoc;    }        private Document getDocumentByUrl(String fileName) throws Exception{      DOMParser parser = new DOMParser();          parser.setFeature("http://xml.org/sax/features/validation", false);          parser.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);          InputStream aa = new FileInputStream(fileName);          parser.parse(new InputSource(aa));          Document doc = parser.getDocument();          aa.close();          return doc;    }
?

热点排行