这个压缩包里的都是超级经典的java例子

源代码在线查看: xsl2dom.htm

软件大小: 2381 K
上传用户: sinoarts
关键词: java 超级
下载地址: 免注册下载 普通下载 VIP

相关代码

				
				
				
				Transforming an XML File with XSL into a DOM Document (Java Developers Almanac Example)
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				
				The Java Developers Almanac 1.4
				
				        Order this book from Amazon.
				    
				
				
				
				
				
				
				
				
				
				
				
				
				
								google_ad_client = "pub-6001183370374757";
				google_ad_width = 120;
				google_ad_height = 600;
				google_ad_format = "120x600_as";
				google_ad_channel = "4777242811";
				google_ad_type = "text_image";
				google_color_border = "FFFFFF";
				google_color_bg = "FFFFFF";
				google_color_link = "6666CC";
				google_color_url = "6666CC";
				google_color_text = "000000";
				//-->   
				
				Home
				    >
				    List of Packages
				    >
				
				    
				    javax.xml.transform
				         [5 examples]
				    
				        >
				        XSL
				             [2 examples]
				            
				
				  e522. Transforming an XML File with XSL into a DOM Document
				
				
				
				    // This method applies the xslFilename to inFilename and
				    // returns DOM document containing the result.
				    public static Document parseXmlFile(String inFilename, String xslFilename) {
				        try {
				            // Create transformer factory
				            TransformerFactory factory = TransformerFactory.newInstance();
				    
				            // Use the factory to create a template containing the xsl file
				            Templates template = factory.newTemplates(new StreamSource(
				                new FileInputStream(xslFilename)));
				    
				            // Use the template to create a transformer
				            Transformer xformer = template.newTransformer();
				    
				            // Prepare the input file
				            Source source = new StreamSource(new FileInputStream(inFilename));
				    
				            // Create a new document to hold the results
				            DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
				            Document doc = builder.newDocument();
				            Result result = new DOMResult(doc);
				    
				            // Apply the xsl file to the source file and create the DOM tree
				            xformer.transform(source, result);
				            return doc;
				        } catch (ParserConfigurationException e) {
				            // An error occurred while creating an empty DOM document
				        } catch (FileNotFoundException e) {
				        } catch (TransformerConfigurationException e) {
				            // An error occurred in the XSL file
				        } catch (TransformerException e) {
				            // An error occurred while applying the XSL file
				        }
				        return null;
				    }
				
				
				
				
				             Related Examples
				
				
				
				
				e521. 
				    The Quintessential Program That Transforms an XML File with XSL
				
				
				
				
				
				
				
				
				© 2002 Addison-Wesley.
				   
				
				
				
				
				
				
				
				
							

相关资源